Cordova-plugin-local-notifications: Actions do not work on fresh install due to conflict with the cordova-plugin-firebase

Created on 11 Dec 2017  路  7Comments  路  Source: katzer/cordova-plugin-local-notifications

Provide a general summary of the issue.

Your Environment

  • Plugin version: 0.9.0-beta1
  • Platform: iOS
  • OS version: iOS 10.3.3
  • Device manufacturer / model: iPhone 6S
  • Cordova version (cordova -v): 7.1.0
  • Cordova platform version (cordova platform ls): ios 4.4.0
  • Plugin config None
  • Ionic Version (if using Ionic) Not using it

Expected Behavior

Action always works.

Actual Behavior

Action doesn't work if app is first installed.

Steps to Reproduce

  1. Install app
  2. Send a notification with action
  3. Notification appears, action button appears
  4. Touch the button and nothing happened.

Context

Actually I already know what is going on. This plugin is in conflict with cordova-plugin-firebase at least version 0.1.24. Both are trying to be delegate for UNUserNotificationCenter. But only one can be at a time. Launching with a fresh install, perhaps I let Firebase ask for permission first, and this plugin lose the delegate status for UNUserNotificationCenter. Subsequent launches do ensure this plugin is the delegate.

This is actually a tricky issue. I don't know what should really be done in this case. Maybe two plugin should actually be a single plugin?

Debug logs

None necessary.

Most helpful comment

I hope this change might help to improve the situation where multiple classes would like to listen for the same delegate.
https://github.com/katzer/cordova-plugin-local-notifications/commit/641ff31a67236fd1db5add911d8fae2047552925

All 7 comments

This problem is also observed with phonegap push plugin

For the moment since I only uses actions for local notifications, I changed APPLocalNotification.m so that it will always reclaim as the delegate when scheduling a notification event. Obviously this is not really satisfactory but it works for my purpose.

- (void) schedule:(CDVInvokedUrlCommand*)command
{
    NSArray* notifications = command.arguments;

    // Add the following hack:
    UNUserNotificationCenter.currentNotificationCenter.delegate = self;

    . . .
}

@t2wu Your solution is working well for me. Could you explain why you think it's not satisfactory?

@awanishraj It wrestles the control away from the remote notification plugin. So actions for remote notification and local notification cannot work at the same time unless you hack some more. What I think really should happen is there should be a third plugin which handles these events and emits them to both the remote notification and the local notification plugins.

I am seeing similar things between iBeacon and Geofencing plugins. I believe these plugins are broken by design.

I also found one solution...run this once window.FirebasePlugin.grantPermission(); after installation of app but for that instance local notification wont work...after that dont run this command again and both of them will start working

I hope this change might help to improve the situation where multiple classes would like to listen for the same delegate.
https://github.com/katzer/cordova-plugin-local-notifications/commit/641ff31a67236fd1db5add911d8fae2047552925

Oh that's a clever method. I finally understand what it does. So notification.request is different between the local notification and the remote ones. It will work as long as it is this plugin that has the control.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tverilytt picture tverilytt  路  4Comments

Shashank2406 picture Shashank2406  路  5Comments

faytekin picture faytekin  路  3Comments

GitToTheHub picture GitToTheHub  路  4Comments

Hirbod picture Hirbod  路  3Comments