Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iOS error when using both Firebasex and Local Notifications: "FirebasePlugin[native]: willPresentNotification: aborting as not a supported UNNotificationTrigger" #230

Closed
AndrewBargan opened this issue Nov 19, 2019 · 11 comments
Labels
caveat A limitation of using this plugin which can't be (easily?) fixed ios relates to iOS platform plugin conflict An issue caused by a conflict with another Cordova plugin runtime issue An issue related to app runtime wontfix

Comments

@AndrewBargan
Copy link

AndrewBargan commented Nov 19, 2019

Current behavior:

We're using cordova-plugin-local-notifications and cordova-plugin-firebasex plugins in our ionic 3 project. When iOS app is in foreground and scheduled local notification should appear it throws
error "FirebasePlugin[native]: willPresentNotification: aborting as not a supported UNNotificationTrigger" instead
I've created minimal ionic 3 project here https://github.com/AndrewBargan/firebasexAndLocalNotificationsBug

Take a look at src/pages/home/home.ts for code that causes problem.

Expected behavior:

Subscription handlers to both firebasex and local notificaitons work simultaneously.

Steps to reproduce:

When app from repository mentioned above built and installed on a real device:

  • Connect Safari to device
  • Open console and keep it open
  • Click "Grant Permissions to Notifications"
  • Click "Schedule Notification in 3 sec"

In 3 seconds error is thrown to console:
"FirebasePlugin[native]: willPresentNotification: aborting as not a supported UNNotificationTrigger"

Screenshot 2019-11-19 at 13 43 23

To reproduce this bug again you need to remove platform and add plugins once again and rebuild the project. For this:

  • Remove installed test app from the iPhone
  • Run: ionic cordova platform rm ios && rm -r plugins && rm -r platforms && ionic cordova platform add ios
  • Set valid app signing profile in xCode
  • Run: ionic cordova build ios -- --buildFlag="-UseModernBuildSystem=0" && ionic cordova run ios --device

Keep in mind you have to put valid GoogleService-Info.plist into the root of the project to make app work.

Environment information

  • Cordova CLI version
    - 9.0.0 (cordova-lib@9.0.1)

  • Cordova platform version
    ios 5.0.1
    Available platforms:
    android ^8.0.0
    browser ^6.0.0
    electron ^1.0.0
    osx ^5.0.0
    windows ^7.0.0

  • Plugins & versions installed in project
    cordova-plugin-androidx 1.0.2 "cordova-plugin-androidx"
    cordova-plugin-androidx-adapter 1.1.0 "cordova-plugin-androidx-adapter"
    cordova-plugin-badge 0.8.8 "Badge"
    cordova-plugin-device 2.0.2 "Device"
    cordova-plugin-firebasex 7.0.1 "Google Firebase Plugin"
    cordova-plugin-ionic-keyboard 2.2.0 "cordova-plugin-ionic-keyboard"
    cordova-plugin-ionic-webview 4.1.3 "cordova-plugin-ionic-webview"
    cordova-plugin-local-notification 0.9.0-beta.2 "LocalNotification"
    cordova-plugin-splashscreen 5.0.2 "Splashscreen"
    cordova-plugin-statusbar 2.4.2 "StatusBar"
    cordova-plugin-whitelist 1.3.3 "Whitelist"

  • Dev machine: macOS 10.15.1

  • Device details: iPhone SE, iOS 13.2.2

  • XCode v11.2.1

BTW: Found issue that looks similar: #95
If it is maybe a good idea to pull from fork of this plugin with the fix that Fabricio Garcia did to the current one.

@dpa99c
Copy link
Owner

dpa99c commented Nov 19, 2019

The problem is that both this plugin and cordova-plugin-local-notifications implements the same UNUserNotificationCenterDelegate willPresentNotification delegate and since delegates have a 1:1 relationship with their parent class, only one of the delegates is being called - in this case, the cordova-plugin-firebasex delegate in response to the notification created by cordova-plugin-local-notifications.
cordova-plugin-firebasex is correctly ignoring a notification which it didn't create so doesn't know how to present (aborting as not a supported UNNotificationTrigger) however the cordova-plugin-local-notifications delegate is not being called because only 1 delegate was invoked, hence you don't get a notification.

This is a conflict between the two plugins (see this SO post for further info about multiple delegates) .
In a native iOS app, you'd simply combine both into a single delegate however due to the nature of Cordova plugins, this isn't a feasible solution.

The best solution would be implement a common shared delegate which broadcast an event which both plugins could add observers for, meaning both plugins would receive the notification event.
However this would require a rework of both plugins and coordination to create/use/maintain such a common component.

Therefore this isn't something that's an easy bugfix and I'm unlikely to attempt to fix this in the near future.
I deem this to be a caveat of using this plugin rather than a bug with it since it functions correctly in isolation and only encounters an issue when another plugin is introduced which makes use of the same native delegates.

FYI I see no commits in the repo in the issue you referenced but please feel free to point out if I have missed that particular piece of code.

@dpa99c dpa99c added ios relates to iOS platform runtime issue An issue related to app runtime caveat A limitation of using this plugin which can't be (easily?) fixed labels Nov 19, 2019
@AndrewBargan
Copy link
Author

Hey @dpa99c,

Thanks for you quick answer!
That's sad. At least good to mention this caveat in the docs that this plugin isn't working in conjunction with local notifications plugin.

Thanks!
Have a good day!

dpa99c pushed a commit that referenced this issue Aug 13, 2020
…iOS"

Upon testing, this plugin does not work with `cordova-plugin-local-notification` present in the same project even with this code in place.
Therefore removing it should stop the crashes occurring in #385.
And the conflict between the 2 plugins will need to be addressed separately under #230.

This reverts commit 4e9a0f4:

> co-existence with cordova-plugin-local-notification on iOS

> Local notifications on iOS via cordova-plugin-local-notification are working again.
>Click-callback for remote notifications not working right now.

>Details:
>UNUserNotificationCenter accepts a single delegate that handles the display of notifications. cordova-plugin-firebase now stores a reference to the existing delegate if any and proxies the delegate-calls (cordova-plugin-local-notification is >already doing that in the other direction when applicable).
@dpa99c
Copy link
Owner

dpa99c commented Aug 13, 2020

Related to this in #443: I believe to resolve this issue, both this plugin and cordova-plugin-local-notification will need to take a different approach to register for app delegate events so they don't conflict.
A possible solution is to extend cordova-plugin-app-event to support the necessary delegates that both plugins can share which should resolve their conflict.
I will investigate the viability of this solution.

@golyo
Copy link

golyo commented Sep 24, 2020

I will investigate the viability of this solution.

Hi @dpa99c !

The problem is the same with release 11.0.1-cli.
"FirebasePlugin[native]: willPresentNotification: aborting as not a supported UNNotificationTrigger"

Could you give me advice how to use it, with cordova-plugin-local-notification plugin ?

Thanks!

@dpa99c
Copy link
Owner

dpa99c commented Sep 24, 2020

@golyo due to the nature of the conflict between this plugin and cordova-plugin-local-notification (both implementing a global delegate method that must be unique) there is no easy solution.
Either you'd need to manually rewrite the native iOS implementation to merge the two implementations or implement an interstitial handler such as I've described above. This is a viable approach but will take considerable effort and also will require changes to both this plugin and cordova-plugin-local-notification to make it work.

@dpa99c dpa99c added the plugin conflict An issue caused by a conflict with another Cordova plugin label Sep 24, 2020
@BradCB
Copy link

BradCB commented Oct 29, 2020

I am using https://github.com/katzer/cordova-plugin-local-notifications version: 0.9.0-beta.3 and https://github.com/wizpanda/cordova-plugin-firebase-lib version: 5.1.1 both are working on iOS. I can fire off background/foreground local and remote notifications.

@dpa99c
I haven't been able to figure out the difference between firebase-lib and your plugin other than the lib is using fabric still. Do you happen to know what it is?

@souly1
Copy link

souly1 commented Dec 13, 2020

Looking at the code in the cordova-local-notification I noticed UNUserNotificationCenter is a singleton and that in must be initialized prior to this plugin via the local notifications plugin, so i created a PR holding previous instance if exists and using it if notification not supported. This behaviour actually seems existent in that plugin (just with instances and not as static).
Forgive my obj-c :P , feel free to improve.

#573

@stale
Copy link

stale bot commented Jun 1, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Jun 1, 2021
@stale stale bot closed this as completed Jun 8, 2021
@jircdev
Copy link

jircdev commented Jan 18, 2023

Could someone solve this problem? Any solution from some plugin?

@miguelp25
Copy link

Still having the same problem...

@TheNotorius0
Copy link

TheNotorius0 commented Jun 15, 2023

I had this problem too, and I resolved it with this code:

    FirebasePlugin.onMessageReceived(function (message) {

        console.log('message', message);

        if (currentPlatform === Platforms.iOS && message.meta && message.meta.plugin === 'cordova-plugin-local-notification-12') {

            return;
        }

        if (message.tap === 'background') {

            return;
        }

        if (message.notification_type === 'notification_queue') {

            ...
        }
        ...
 });

When you receive a notification from the local-notification-plugin, you can see it in the message.meta.plugin property.

Since I don't need to do anything when my local notification triggers, I just return, but you can do your custom logic there I guess, like showing a popup.

PS: note that I'm using cordova-plugin-local-notification-12, but you can change it with the plugin you're using

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
caveat A limitation of using this plugin which can't be (easily?) fixed ios relates to iOS platform plugin conflict An issue caused by a conflict with another Cordova plugin runtime issue An issue related to app runtime wontfix
Projects
None yet
Development

No branches or pull requests

8 participants