Flutterfire: [firebase_messaging] fcm notifications not working in release mode

Created on 6 Oct 2019  Â·  15Comments  Â·  Source: FirebaseExtended/flutterfire

Describe the bug
I wrote a small app to generate fcm token. I use this token to send a notification to my app with firebase admin sdk. It works perfectly fine when i build and install debug app on my ios device. The problem is in release build of the app. I always get token not registered error.

{ 
  code: 'messaging/registration-token-not-registered',                                                          message: 'The provided registration token is not registered. A previously valid registration token can be unregistered for a variety of reasons. See the error documentation for more details. Remove this registration token and stop using it to send messages.' },
  codePrefix: 'messaging' 
} 

To Reproduce
Steps to reproduce the behavior:

  1. Build debug app to generate fcm and install on iOS device
  2. Get token
  3. Send notification to app via notification composer or admin sdk. Confirm notification
  4. Build release app to generate fcm and install on iOS device
  5. Send notification to app via notification composer or admin sdk. No notification.
    Instead we see above error if sent via admin sdk.

Expected behavior
Notification should be seen in app in release mode

Additional context
I am using the same app identifier "com.example.fcm..." for both debug and release, so this eliminates the need to generate another set of identifier/provisioning profile, certificates and APNs.

My output of flutter doctor:

[✓] Flutter (Channel stable, v1.9.1+hotfix.4, on Mac OS X 10.14.6
    18G103, locale en-US)
    • Flutter version 1.9.1+hotfix.4 at
      /Users/.../flutter
    • Framework revision cc949a8e8b (9 days ago), 2019-09-27 15:04:59
      -0700
    • Engine revision b863200c37
    • Dart version 2.5.0


[✓] Android toolchain - develop for Android devices (Android SDK 
    version 28.0.3)
    • Android SDK at /Users/.../Library/Android/sdk
    • Android NDK location not configured (optional; useful for native
      profiling support)
    • Platform android-28, build-tools 28.0.3
    • Java binary at: /Applications/Android
      Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build
      1.8.0_152-release-1136-b06)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 11.0)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 11.0, Build version 11A420a
    • CocoaPods version 1.7.5

[!] Android Studio (version 3.2)
    • Android Studio at /Applications/Android Studio.app/Contents
    ✗ Flutter plugin not installed; this adds Flutter specific
      functionality.
    ✗ Dart plugin not installed; this adds Dart specific
      functionality.
    • Java version OpenJDK Runtime Environment (build
      1.8.0_152-release-1136-b06)

[✓] VS Code (version 1.38.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.5.1

[✓] Connected device (1 available)
    •iPhone • 1c65d688b4859230d0f603c22144033caaa63b43 •
      ios • iOS 12.4.2

! Doctor found issues in 1 category.
messaging bug documentation

All 15 comments

have same problem...

Any updates on this?

Never mind, this can be solved by building the app with App Store certificates and deploying it to test devices using TestFlight.

Never mind, this can be solved by building the app with App Store certificates and deploying it to test devices using TestFlight.

please, what do u mean with appstore certificate? how do you build it with that? also you can't build -release on iphone without test flight and the notifications working?

I have the same issue ...

I have the same issue and I am hard stuck at this.

It used to work with older versions of firebase_messaging, however, the latest version is not working for me.

Note: I also use the flutter_local_notifications, but everything is setup according to the documentation.

Hey all 👋

As part of our roadmap (#2582) we've just shipped a complete rework of the firebase_messaging plugin that aims to solve this and many other issues.

If you can, please try out the dev release (see the migration guide for upgrading and for changes) and if you have any feedback then join in the discussion here.

Given the scope of the rework I'm going to go ahead and close this issue in favor of trying out the latest plugin.

Thanks everyone 🤓

Hi all. I am currently experiencing this issue. I was getting notification in the previous version but onMessage method didn't work. I recently updated firebase_messaging and now I cannot receive notifications in release mode. If I debug on simulator or on physical device I do get the notifications correctly. I have the certificates created and placed on appropriate places.

Can any one help. ?

Thanks.

@muzammil22, I had the same issue when was using flutter run --release.

You can try this, archive the app and upload your build to AppStore Connect. Then install it to your phone using TestFlight.

This worked for me.

I create a build using xcode and donot deploy it on app store connect. Instead I click development and get the .ipa file. Then I distribute the .ipa file using another service.
And it doesn't work this way. I have been trying to fix it for 2 days now.

I create a build using xcode and donot deploy it on app store connect. Instead I click development and get the .ipa file. Then I distribute the .ipa file using another service.
And it doesn't work this way. I have been trying to fix it for 2 days now.

@muzammil22, I know, I had similar experience as you when I tried to distribute with Firebase App Distribution.

The whole point is to put it in App Store Connect and download it with Test Flight. I think this weird behavior is related with the APNs certificates.

Okay. I'll try to do this.

I do get the notifications when the app is in background or closed but doesn't receive notifications when it's running. I added a Toast in onMessage and onResume to check. It doesn't show that.
Anyone experiencing the same issue ?

Isn't this method available in the latest and stable version 7.0.3 or 7.0.0 ?
Plus how come the foreground notifications work currently on simulator but not when I build the app ?

Was this page helpful?
0 / 5 - 0 ratings