MaikuB / flutter_local_notifications

A Flutter plugin for displaying local notifications on Android, iOS, macOS and Linux
2.46k stars 1.4k forks source link

firebase_messaging + flutter_local_notifications #1212

Closed deepak786 closed 3 years ago

deepak786 commented 3 years ago

Not able to use both packages in the same app in iOS. Checked all the other threads and related issue. There is no proper solution to make them work together on iOS.

Using the below package versions in the app.

flutter_local_notifications: 6.0.0
firebase_messaging: 10.0.2
  1. If only firebase_messaging: 10.0.2 is used then all the background and foreground messages and their logs are working fine on both Android and iOS.
  2. if used both firebase_messaging: 10.0.2 and flutter_local_notifications: 6.0.0 then everything is working fine on Android. But on iOS:
    • foreground messages are not working.
    • the background notifications are working but the respective logs or code to handle the background message is not working.
    • If we click on the notification which is received in the background then the below error appears:
      UNUserNotificationCenter delegate received call to -userNotificationCenter:didReceiveNotificationResponse:withCompletionHandler: but the completion handler was never called.
am1tr0r commented 3 years ago

facing the same issue

MaikuB commented 3 years ago

Can you provide a link to a repository containing a complete minimal app that can reproduce the issue but don't include the firebase configuration file?

deepak786 commented 3 years ago

Here is the sample https://github.com/deepak786/flutter_notifications_issue

It seems that the sample is working fine. In our app, we have the same code but their notifications are not working.

Is that due to some other dependency conflict? Here is the pubspec.yml file from the main app.

pubspec.yml ``` flutter_keyboard_visibility: 5.0.0 provider: 5.0.0 url_launcher: 6.0.3 bot_toast: 4.0.1 #visibility_detector: ^0.1.5 flutter_svg: 0.21.0+1 firebase_core: 1.3.0 firebase_auth: 1.2.0 firebase_analytics: 8.1.0 firebase_crashlytics: 2.0.4 firebase_database: 7.0.0 firebase_storage: 8.1.0 firebase_dynamic_links: 2.0.4 firebase_messaging: 10.0.2 cloud_firestore: 2.2.0 cloud_functions: 1.1.0 flutter_switch: 0.3.0 shared_preferences: 2.0.5 json_annotation: 3.1.1 collection: 1.15.0 image_picker: 0.7.4 image_cropper: 1.4.0 cached_network_image: 3.0.0 flutter_cache_manager: 3.0.1 diacritic: 0.1.3 flutter_sticky_header: 0.6.0 intercom_flutter: 3.1.0 device_info_plus: 1.0.0 crypto: 3.0.1 encrypt: 5.0.0 numberpicker: 2.1.1 pdf: 3.3.0 printing: 5.2.0 image: 3.0.2 flutter_signature_pad: 3.0.0 share_plus: ^2.0.1 async: 2.7.0 connectivity_plus: 1.0.0 auto_size_text: 3.0.0-nullsafety.0 charts_flutter: 0.10.0 styled_text: 3.0.1 flutter_udid: 2.0.0 fingerprintjs: 1.0.4 flutter_local_notifications: 6.0.0 ```

_Note: Notifications are working fine in our main app without this flutter_local_notifications package._

deepak786 commented 3 years ago

Added the property IntercomAutoIntegratePushNotifications with a value of NO in Info.plist and then foreground notifications are working fine in our main app as we also used the dependency intercom_flutter.

Now we have the following issues with iOS:

  1. If the iOS app is in the background then our background handler, setUp with Firebase Messaging, is not getting called and logs are not shown but the notifications are working.
  2. Due to not getting called the method background handler, the app is not receiving the data messages from FCM.

The above issues are reproducible in the sample code https://github.com/deepak786/flutter_notifications_issue

MaikuB commented 3 years ago

Sounds like you are having issues with more dependencies than you've originally mentioned. I suggest you try removing said dependencies to narrow down the cause as you potentially need to log that issue with whoever maintains the package. For example, have you tried remove the intercom_flutter package? Based on what you've written, it's interfering with the receiving of messages from FCM, in which case, that's not an issue with this plugin. Note I'm not able to look at issues involving other dependencies besides firebase_messaging. It may be possible that if you need integrate FCM, local notifications and intercom that you need to write all of the iOS code yourself or look to see what changes can be made to this plugin so that they all work together via a PR

deepak786 commented 3 years ago

@MaikuB as I already said the only issue is that onBackgroundHandler is not getting called. The issue is reproducible in sample. In the sample, I'm not using any dependencies that can conflict.

MaikuB commented 3 years ago

Got it. Had some confusion as you originally wrote the sample worked fine but not the main app so thought you went to add the intercom dependency to the sample to illustrate it though I hadn't gotten the chance to look at it yet

mu-dawood commented 3 years ago

try fcm_config

MaikuB commented 3 years ago

@deepak786 the example app you've provided fails with the following error

error: The file "/Users/michaelbui/Projects/GitHub/flutter_notifications_issue/ios/ImageNotification/ImageNotification.entitlements" could not be opened. Verify the value of the CODE_SIGN_ENTITLEMENTS build setting for target "ImageNotification" is correct and that the file exists on disk. (in target 'ImageNotification' from project 'Runner')

In the mean time, I tried reproducing the issue you've reported with an example I've had for a while and updated recently and don't see the issue. It can be found https://github.com/MaikuB/flutter_firebase_local_notifications_examples/tree/master/kotlin_swift. Steps I've followed are to run the app in release mode, put it in the background and send a notification from the server and making sure the payload has content_available set to true. This is a requirement for background notifications to caught. Wondering if you've missed this as when there are compatibility issues between these plugins, it would impact both foreground and background scenarios

deepak786 commented 3 years ago

I have tried already with content_available to true in the payload. It seems that the issue is in the firebase_messaging plugin. check https://github.com/FirebaseExtended/flutterfire/issues/6290

MaikuB commented 3 years ago

Closing this then as it's not an issue with this plugin

kevinarch commented 3 years ago

@MaikuB don't you think flutter_local_notifications was fighting with firebase-messaging for UNNotificationCenter delegation control ?

MaikuB commented 3 years ago

No as the original issue that was reported had nothing to do with this plugin even (i.e. the background messaging issue would occur even there wasn't a dependency on this plugin) and as mentioned earlier, I was able to get notifications running from both. The FCM example app actually includes this plugin as a dependency so if there were conflicts, the maintainers of the FCM plugin would've identified that as well