ionic-team / capacitor-plugins

Official plugins for Capacitor ⚡️
528 stars 592 forks source link

PushNotification does not trigger pushNotificationReceived and pushNotificationActionPerformed #800

Closed hembachrterran closed 2 years ago

hembachrterran commented 2 years ago

Bug Report

Plugin(s)

@capacitor/push-notifications

Capacitor Version

Capacitor Doctor
Latest Dependencies:
  @capacitor/cli: 3.4.0
  @capacitor/core: 3.4.0
  @capacitor/android: 3.4.0
  @capacitor/ios: 3.4.0
Installed Dependencies:
  @capacitor/android: 3.4.0
  @capacitor/cli: 3.4.0
  @capacitor/core: 3.4.0
  @capacitor/ios: 3.4.0

Platform(s)

[x] iOS

Current Behavior

I followed this https://capacitorjs.com/docs/guides/push-notifications-firebase documentation, I would like to use this plugin with FCM. The PushNotifications.register() called properly and "registration" listener is triggered, returned a token. By the token the test message arrive to the phone and show a notification with the proper title and body, but the "pushNotificationReceived " listener and after click on the notification the "pushNotificationActionPerformed" doesn't fire. I tried everything to figure out what's the problem, but I have no clue. In the listeners there is only a console log, I copy and paste the code from the example.

Expected Behavior

The listeners print to the console, the notification data.

Code Reproduction

The code is presented in the example of the following link: https://capacitorjs.com/docs/guides/push-notifications-firebase

Other Technical Details

XCode 13.2.1 The phone is an iPhone 11 with latest updates. The Push Notification capability is enabled.

Additional Context

This problems seems related with https://github.com/ionic-team/capacitor-plugins/issues/200

Ionitron commented 2 years ago

This issue may need more information before it can be addressed. In particular, it will need a reliable Code Reproduction that demonstrates the issue.

Please see the Contributing Guide for how to create a Code Reproduction.

Thanks! Ionitron 💙

hembachrterran commented 2 years ago

@josprimasihombing Yes, same here. @jcesarmobile The example code needs to set up Firebase as @josprimasihombing wrote, thats why I linked the example, I used the same code.

jcesarmobile commented 2 years ago

I can switch the configuration files to use my own once you provide the sample app, but without a sample app this can’t be reproduced, you probably missed some step.

hembachrterran commented 2 years ago

Okay, I will provide it soon.

spasma commented 2 years ago

I've got the same issue, pushNotificationActionPerformed in my case.

I'm still not certain about it, but It seems like this event is not triggering if the app is in a sleep state in the background. It does not occur directly after we move the app to the background, but after iOS has truncated memory (or put the app in a sleep state?).

hembachrterran commented 2 years ago

I made a sample application, the plugin work as expected, if the app is running in foregroung, it triggered the pushNotificationActionPerformed. I have been skipped one step on Apple website with the signatures, the https://capacitorjs.com/docs/guides/push-notifications-firebase documentation is not as detailed as has to be in my opinion.

hembachrterran commented 2 years ago

@josprimasihombing When you create certifications in Developer https://developer.apple.com/account/resources/certificates/list, you have to set up an Identifier before: https://developer.apple.com/account/resources/identifiers/list. There you have to allow the PushNotification service Capability, after you created it, you can select it from the list to edit. There will be a Configure button where you can create a Development SSL Certificate or Production SSL Certificate. In next step you have to upload a Certificate Signing Request from your Mac. Hard to notice but above the input, there is a learn more link: https://help.apple.com/developer-account/#/devbfa00fef7 Following this documentation you can create the signing request on your local computer then upload and save the capability certification on Apple website.

hembachrterran commented 2 years ago

@jcesarmobile I find out the differences. In the application I want to use this plugin also we use the "https://ionicframework.com/docs/native/background-geolocation" plugin. It seem the background geolocation plugin is incompatible with this push notification plugin. I have no more detail what part of the plugin caused the problem, but 100% sure this is why pushNotificationReceived and pushNotificationActionPerformed events has not been triggered, after uninstall the background geolocation plugin the events fires properly.

jcesarmobile commented 2 years ago

That plugin has its own UNUserNotificationCenterDelegate, that's what handles the notifications and apps can only have one, so when you install that plugin it sets itself as the notifications delegate and the events don't get propagated to Capacitor push/local-notification plugins.

hembachrterran commented 2 years ago

It would be nice if mention this in the documentations.

ionitron-bot[bot] commented 2 years ago

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of the plugin, please create a new issue and ensure the template is fully filled out.