flutterfire icon indicating copy to clipboard operation
flutterfire copied to clipboard

🐛 [firebase_messaging] FCM not working in iOS (dart initialisation)

Open rashid-abdulla opened this issue 4 years ago • 18 comments

Bug report

FCM works perfectly in Android but not in iOS. Tried both in background and foreground message, Data & Notification messages

Steps to reproduce

Steps to reproduce the behaviour:

  1. Implement firebase core along with firebase messaging in dart.
  2. Complete apple by creating a key, uploading the APNS key to firebase and verifying the provisioning profile.
  3. Send push notification from either via REST API (I've used the example app of the package or from the firebase console).

Expected behaviour

A notification should be received on an ios device.


Flutter doctor

Click To Expand
abdullarashidm@Abdullas-MacBook-Air fcm % flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 2.8.1, on macOS 12.0.1 21A559 darwin-arm, locale en-IN)
[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 13.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2020.3)
[✓] VS Code (version 1.63.2)
[✓] Connected device (1 available)

• No issues found!

Flutter dependencies

Click To Expand
Dart SDK 2.15.1
Flutter SDK 2.8.1
fcm 1.0.0+1

dependencies:
- cupertino_icons 1.0.4
- firebase_core 1.10.6 [firebase_core_platform_interface firebase_core_web flutter meta]
- firebase_messaging 11.2.4 [firebase_core firebase_core_platform_interface firebase_messaging_platform_interface firebase_messaging_web flutter meta]
- flutter 0.0.0 [characters collection meta typed_data vector_math sky_engine]
- flutter_local_notifications 9.2.0 [clock flutter flutter_local_notifications_linux flutter_local_notifications_platform_interface timezone]
- http 0.13.4 [async http_parser meta path]

dev dependencies:
- flutter_lints 1.0.4 [lints]
- flutter_test 0.0.0 [flutter test_api path fake_async clock stack_trace vector_math async boolean_selector characters charcode collection matcher meta source_span stream_channel string_scanner term_glyph typed_data]

transitive dependencies:
- args 2.3.0
- async 2.8.2 [collection meta]
- boolean_selector 2.1.0 [source_span string_scanner]
- characters 1.2.0
- charcode 1.3.1
- clock 1.1.0
- collection 1.15.0
- dbus 0.6.6 [args ffi meta xml]
- fake_async 1.2.0 [clock collection]
- ffi 1.1.2
- file 6.1.2 [meta path]
- firebase_core_platform_interface 4.2.3 [collection flutter meta plugin_platform_interface]
- firebase_core_web 1.5.3 [firebase_core_platform_interface flutter flutter_web_plugins js meta]
- firebase_messaging_platform_interface 3.1.4 [firebase_core flutter meta plugin_platform_interface]
- firebase_messaging_web 2.2.5 [firebase_core firebase_core_web firebase_messaging_platform_interface flutter flutter_web_plugins js meta]
- flutter_local_notifications_linux 0.4.1+1 [flutter flutter_local_notifications_platform_interface dbus path xdg_directories]
- flutter_local_notifications_platform_interface 5.0.0 [flutter plugin_platform_interface]
- flutter_web_plugins 0.0.0 [flutter js characters collection meta typed_data vector_math]
- http_parser 4.0.0 [charcode collection source_span string_scanner typed_data]
- js 0.6.3
- lints 1.0.1
- matcher 0.12.11 [stack_trace]
- meta 1.7.0
- path 1.8.0
- petitparser 4.4.0 [meta]
- platform 3.1.0
- plugin_platform_interface 2.0.2 [meta]
- process 4.2.4 [file path platform]
- sky_engine 0.0.99
- source_span 1.8.1 [collection path term_glyph]
- stack_trace 1.10.0 [path]
- stream_channel 2.1.0 [async]
- string_scanner 1.1.0 [charcode source_span]
- term_glyph 1.2.0
- test_api 0.4.3 [async boolean_selector collection meta source_span stack_trace stream_channel string_scanner term_glyph matcher]
- timezone 0.8.0 [path]
- typed_data 1.3.0 [collection]
- vector_math 2.1.1
- xdg_directories 0.2.0 [meta path process]
- xml 5.3.1 [collection meta petitparser]

rashid-abdulla avatar Jan 02 '22 14:01 rashid-abdulla

@abdulllrashid Does this happen when you initialize through dart or without it too ? Does any of the streams onMessage, onMessageOpenedApp, onBackgroundMessage trigger ? Can you also provide a sample payload you are sending ?

darshankawar avatar Jan 03 '22 10:01 darshankawar

I am also having a similar issue. I'm able to receive a notification using the Test mode in the firebase console but a normal notification via the console never get's received by the device.

caleb654 avatar Jan 08 '22 16:01 caleb654

@caleb654 please confirm if this happens with Dart initialization or with manual installation too.

pr-Mais avatar Jan 10 '22 07:01 pr-Mais

Initialization

@darshankawar This happens with dart initialization.

I've also tried with the manual installation, and the issue persisted. I'm not sure my manual installation is correct since the latest manual installation doc is confusing a little. The new docs ask to add the googleservice-info.plist, and we're done. This simplicity is confusing me. In older times we used to add reverse client id and all in info.plist while the latest doc isn't. It might be another issue. However, with my manual setup, my ios device isn't receiving any notifications.

Streams

The streams onMessage, onMessageOpenedApp, onBackgroundMessage isn't getting triggered anytime, while the app is in foreground/background/terminated.

Payload

I'm trying to send notifications from firebase console primarily for testing. My regular payload will be

Click To Expand
        $notification = array(
            'title'                 => $post_title,
            'body'                  => $post_content,
            'sound'                 => 'default',
            'image'                 => $image,   
        );
        $data = array(
            'message'               => $post_content,
            'title'                 => $post_title,
            'image'                 => $image,
            'id'                    => $post_id,
        );   
        $post = array(
            'condition'         => "'post' in topics",
            'notification'      => $notification,
            'content_available' => true,
            'priority'          => 'high',
            'data'              => $data
        );

rashid-abdulla avatar Jan 11 '22 06:01 rashid-abdulla

Are you testing on a real iOS device or simulator?

pr-Mais avatar Jan 11 '22 07:01 pr-Mais

on real ios Device @pr-Mais

rashid-abdulla avatar Jan 11 '22 09:01 rashid-abdulla

@abdulllrashid Can you confirm following:

  • Requested notification permissions on the device ? Is the notification sent successfully if you send it directly to the FCM token?
  • Package identifier is the same as in the apple configuration?
  • Check APNs certificate from Firebase, Cloud Messaging, iOS
  • Debug certificate is valid or expired
  • Try to remove certificate from Firebase and re-generate it and add as applicable (firebase, cloud messaging and iOS config).

darshankawar avatar Jan 12 '22 10:01 darshankawar

@caleb654 please confirm if this happens with Dart initialization or with manual installation too.

Dart initialization. I haven't tested it the the manual install.

caleb654 avatar Jan 12 '22 20:01 caleb654

Hey @abdulllrashid. We need more information to resolve this issue but there hasn't been an update in 7 weekdays. I'm marking the issue as stale and if there are no new updates in the next 7 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!

google-oss-bot avatar Jan 21 '22 02:01 google-oss-bot

@abdulllrashid Can you confirm following:

  • Requested notification permissions on the device ? Is the notification sent successfully if you send it directly to the FCM token?
  • Package identifier is the same as in the apple configuration?
  • Check APNs certificate from Firebase, Cloud Messaging, iOS
  • Debug certificate is valid or expired
  • Try to remove certificate from Firebase and re-generate it and add as applicable (firebase, cloud messaging and iOS config).

We faced the same issue after migrated to Dart initialization and removed GoogleService-Info.plist and google-services.json files. We fixed with putting back these files to project.

suleymancalik avatar Jan 21 '22 07:01 suleymancalik

It seems a bit redundant with the usage of FirebaseMessaging.instance.setForegroundNotificationPresentationOptions, but using the initialization in AppDelegate from this doc seems to have fixed this for my team:

if #available(iOS 10.0, *) {
  // For iOS 10 display notification (sent via APNS)
  UNUserNotificationCenter.current().delegate = self

  let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
  UNUserNotificationCenter.current().requestAuthorization(
    options: authOptions,
    completionHandler: { _, _ in }
  )
} else {
  let settings: UIUserNotificationSettings =
    UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)
  application.registerUserNotificationSettings(settings)
}

application.registerForRemoteNotifications()

ericomine avatar Jan 26 '22 19:01 ericomine

Hey @abdulllrashid. We need more information to resolve this issue but there hasn't been an update in 7 weekdays. I'm marking the issue as stale and if there are no new updates in the next 7 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!

google-oss-bot avatar Feb 04 '22 02:02 google-oss-bot

I am also having this issue - same as the above, no issues on Android - only on iOS. I didn't have issues before updating to dart initialization, what I am seeing on my iOS device (not simulator):

APNS device token not set before retrieving FCM Token for Sender ID

I have followed the docs again to be sure, but I am really hesitant to re-add the APNS key as the application is live in prod. Debug certificate/profile is all being managed by xCode and should be fine.

EDIT: Swapped out the Dart initiliaztion for .plist and i'm back up and running.

ItsCalebJones avatar Feb 04 '22 05:02 ItsCalebJones

Hello,

Same issue.

By default we integrate Firebase natively for iOS and Android. To be up to date, we migrated our native integration to the Dart initilization and now we have this problem on iOS.

We tried the tips suggested by @ericomine without success.

We send our notifications directly from console.firebase.google.com

flutter doctor :

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 2.10.0, on macOS 12.1 21C52 darwin-arm, locale en-FR)
[✓] Android toolchain - develop for Android devices (Android SDK version 32.1.0-rc1)
[✓] Xcode - develop for iOS and macOS (Xcode 13.2.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2021.1)
[✓] VS Code (version 1.63.2)
[✓] Connected device (2 available)
[✓] HTTP Host Availability

pubspec.lock :

 firebase_analytics:
    dependency: "direct main"
    description:
      name: firebase_analytics
      url: "https://pub.dartlang.org"
    source: hosted
    version: "9.1.0"
  firebase_analytics_platform_interface:
    dependency: transitive
    description:
      name: firebase_analytics_platform_interface
      url: "https://pub.dartlang.org"
    source: hosted
    version: "3.0.5"
  firebase_analytics_web:
    dependency: transitive
    description:
      name: firebase_analytics_web
      url: "https://pub.dartlang.org"
    source: hosted
    version: "0.4.0+6"
  firebase_core:
    dependency: "direct main"
    description:
      name: firebase_core
      url: "https://pub.dartlang.org"
    source: hosted
    version: "1.12.0"
  firebase_core_platform_interface:
    dependency: transitive
    description:
      name: firebase_core_platform_interface
      url: "https://pub.dartlang.org"
    source: hosted
    version: "4.2.4"
  firebase_core_web:
    dependency: transitive
    description:
      name: firebase_core_web
      url: "https://pub.dartlang.org"
    source: hosted
    version: "1.5.4"
  firebase_crashlytics:
    dependency: "direct main"
    description:
      name: firebase_crashlytics
      url: "https://pub.dartlang.org"
    source: hosted
    version: "2.5.0"
  firebase_crashlytics_platform_interface:
    dependency: transitive
    description:
      name: firebase_crashlytics_platform_interface
      url: "https://pub.dartlang.org"
    source: hosted
    version: "3.1.13"
  firebase_dynamic_links:
    dependency: "direct main"
    description:
      name: firebase_dynamic_links
      url: "https://pub.dartlang.org"
    source: hosted
    version: "4.0.5"
  firebase_dynamic_links_platform_interface:
    dependency: transitive
    description:
      name: firebase_dynamic_links_platform_interface
      url: "https://pub.dartlang.org"
    source: hosted
    version: "0.2.0+5"
  firebase_messaging:
    dependency: "direct main"
    description:
      name: firebase_messaging
      url: "https://pub.dartlang.org"
    source: hosted
    version: "11.2.6"
  firebase_messaging_platform_interface:
    dependency: transitive
    description:
      name: firebase_messaging_platform_interface
      url: "https://pub.dartlang.org"
    source: hosted
    version: "3.1.6"
  firebase_messaging_web:
    dependency: transitive
    description:
      name: firebase_messaging_web
      url: "https://pub.dartlang.org"
    source: hosted
    version: "2.2.7"

Podfile.lock :

- Firebase/Analytics (8.11.0):
    - Firebase/Core
  - Firebase/Core (8.11.0):
    - Firebase/CoreOnly
    - FirebaseAnalytics (~> 8.11.0)
  - Firebase/CoreOnly (8.11.0):
    - FirebaseCore (= 8.11.0)
  - Firebase/Crashlytics (8.11.0):
    - Firebase/CoreOnly
    - FirebaseCrashlytics (~> 8.11.0)
  - Firebase/DynamicLinks (8.11.0):
    - Firebase/CoreOnly
    - FirebaseDynamicLinks (~> 8.11.0)
  - Firebase/Messaging (8.11.0):
    - Firebase/CoreOnly
    - FirebaseMessaging (~> 8.11.0)
  - firebase_analytics (9.1.0):
    - Firebase/Analytics (= 8.11.0)
    - firebase_core
    - Flutter
  - firebase_core (1.12.0):
    - Firebase/CoreOnly (= 8.11.0)
    - Flutter
  - firebase_crashlytics (2.5.0):
    - Firebase/Crashlytics (= 8.11.0)
    - firebase_core
    - Flutter
  - firebase_dynamic_links (4.0.5):
    - Firebase/DynamicLinks (= 8.11.0)
    - firebase_core
    - Flutter
  - firebase_messaging (11.2.6):
    - Firebase/Messaging (= 8.11.0)
    - firebase_core
    - Flutter
  - FirebaseAnalytics (8.11.0):
    - FirebaseAnalytics/AdIdSupport (= 8.11.0)
    - FirebaseCore (~> 8.0)
    - FirebaseInstallations (~> 8.0)
    - GoogleUtilities/AppDelegateSwizzler (~> 7.7)
    - GoogleUtilities/MethodSwizzler (~> 7.7)
    - GoogleUtilities/Network (~> 7.7)
    - "GoogleUtilities/NSData+zlib (~> 7.7)"
    - nanopb (~> 2.30908.0)
  - FirebaseAnalytics/AdIdSupport (8.11.0):
    - FirebaseCore (~> 8.0)
    - FirebaseInstallations (~> 8.0)
    - GoogleAppMeasurement (= 8.11.0)
    - GoogleUtilities/AppDelegateSwizzler (~> 7.7)
    - GoogleUtilities/MethodSwizzler (~> 7.7)
    - GoogleUtilities/Network (~> 7.7)
    - "GoogleUtilities/NSData+zlib (~> 7.7)"
    - nanopb (~> 2.30908.0)
  - FirebaseCore (8.11.0):
    - FirebaseCoreDiagnostics (~> 8.0)
    - GoogleUtilities/Environment (~> 7.7)
    - GoogleUtilities/Logger (~> 7.7)
  - FirebaseCoreDiagnostics (8.11.0):
    - GoogleDataTransport (~> 9.1)
    - GoogleUtilities/Environment (~> 7.7)
    - GoogleUtilities/Logger (~> 7.7)
    - nanopb (~> 2.30908.0)
  - FirebaseCrashlytics (8.11.0):
    - FirebaseCore (~> 8.0)
    - FirebaseInstallations (~> 8.0)
    - GoogleDataTransport (~> 9.1)
    - GoogleUtilities/Environment (~> 7.7)
    - nanopb (~> 2.30908.0)
    - PromisesObjC (< 3.0, >= 1.2)
  - FirebaseDynamicLinks (8.11.0):
    - FirebaseCore (~> 8.0)
  - FirebaseInstallations (8.11.0):
    - FirebaseCore (~> 8.0)
    - GoogleUtilities/Environment (~> 7.7)
    - GoogleUtilities/UserDefaults (~> 7.7)
    - PromisesObjC (< 3.0, >= 1.2)
  - FirebaseMessaging (8.11.0):
    - FirebaseCore (~> 8.0)
    - FirebaseInstallations (~> 8.0)
    - GoogleDataTransport (~> 9.1)
    - GoogleUtilities/AppDelegateSwizzler (~> 7.7)
    - GoogleUtilities/Environment (~> 7.7)
    - GoogleUtilities/Reachability (~> 7.7)
    - GoogleUtilities/UserDefaults (~> 7.7)
    - nanopb (~> 2.30908.0)

Thank for your help

atnpem avatar Feb 04 '22 20:02 atnpem

@antoinepemeja Actually, for me it was a false positive. I do not know what happened, but notifications worked once with a colleagues' machine/phone after we made that change, but then it didn't work anywhere else.

A couple of days after that happened, the firebase_messaging package got updated to 11.2.6 and that has fixed for us. We are currently running QA tests and push notifications seems to be working fine in iOS since we updated it. I see you're already using this version, so I guess this doesn't help a lot...

ericomine avatar Feb 04 '22 21:02 ericomine

@ericomine I created a build from Bitrise (to be in another context/environment) and it works. So I think our problem is linked with our local environment (cache maybe).

atnpem avatar Feb 05 '22 13:02 atnpem

Hey @abdulllrashid. We need more information to resolve this issue but there hasn't been an update in 7 weekdays. I'm marking the issue as stale and if there are no new updates in the next 7 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!

google-oss-bot avatar Feb 15 '22 02:02 google-oss-bot

Since there haven't been any recent updates here, I am going to close this issue.

@abdulllrashid if you're still experiencing this problem and want to continue the discussion just leave a comment here and we are happy to re-open this.

google-oss-bot avatar Feb 24 '22 02:02 google-oss-bot