flutterfire icon indicating copy to clipboard operation
flutterfire copied to clipboard

[firebase_messaging] No Message in iOS Release Mode

Open tuanha2000vn opened this issue 6 years ago β€’ 30 comments

Describe the bug Android Debug: Work Android Release: Work iOS Debug: Work iOS Release: Not Work

To Reproduce

Steps to reproduce the behavior:

  1. Clone sample app: https://github.com/tuanha2000vn/fcm_ios_release_bug
  2. Build iOS App and click the button 'https://fcm.googleapis.com/fcm/send'
  3. Notice the difference of iOS app in Debug Mode vs Release Mode result

Expected behavior Send data:

{
 "to" : "d944GNsO90n6mOdYPd21hl:APA91bF7SONl9E7E4sFhtTdKeH_Zmesh_n1KJAWE_y7Kod8z9RSa8hHFMKELv0WHGUAGdxdiZVwNYPyPTxSxODIE-e8wyqKs2C-lhQ6JPocxJmZueMiTfRj-HcD-QvqRXpGIefj4K-Nw",
 "collapse_key" : "type_a",
 "notification" : {
     "body" : "Body of Your Notification",
     "title": "Title of Your Notification"
 },
 "data" : {
     "body" : "Body of Your Notification in Data",
     "title": "Title of Your Notification in Title",
     "key_1" : "Value for key_1",
     "key_2" : "Value for key_2"
 }
}

iOS Debug:

{
    "multicast_id": 2894437391698496198,
    "success": 1,
    "failure": 0,
    "canonical_ids": 0,
    "results": [
        {
            "message_id": "1590877840476643"
        }
    ]
}

iOS Release:

{
    "multicast_id": 1281464412959576484,
    "success": 0,
    "failure": 1,
    "canonical_ids": 0,
    "results": [
        {
            "error": "InvalidRegistration"
        }
    ]
}

Additional context pubspec.yaml

name: hassdash
description: A new Flutter application.

# The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43
# followed by an optional build number separated by a +.
# Both the version and the builder number may be overridden in flutter
# build by specifying --build-name and --build-number, respectively.
# In Android, build-name is used as versionName while build-number used as versionCode.
# Read more about Android versioning at https://developer.android.com/studio/publish/versioning
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.0.0+1

environment:
  sdk: ">=2.1.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter

  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^0.1.2
  firebase_analytics: any
  firebase_messaging: 6.0.16
  firebase_core: ^0.4.0

dev_dependencies:
  flutter_test:
    sdk: flutter

# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec

# The following section is specific to Flutter.
flutter:
  # The following line ensures that the Material Icons font is
  # included with your application, so that you can use the icons in
  # the material Icons class.
  uses-material-design: true
  # To add assets to your application, add an assets section, like this:
  # assets:
  #  - images/a_dot_burr.jpeg
  #  - images/a_dot_ham.jpeg
  # An image asset can refer to one or more resolution-specific "variants", see
  # https://flutter.dev/assets-and-images/#resolution-aware.
  # For details regarding adding assets from package dependencies, see
  # https://flutter.dev/assets-and-images/#from-packages
  # To add custom fonts to your application, add a fonts section here,
  # in this "flutter" section. Each entry in this list should have a
  # "family" key with the font family name, and a "fonts" key with a
  # list giving the asset and other descriptors for the font. For
  # example:
  # fonts:
  #   - family: Schyler
  #     fonts:
  #       - asset: fonts/Schyler-Regular.ttf
  #       - asset: fonts/Schyler-Italic.ttf
  #         style: italic
  #   - family: Trajan Pro
  #     fonts:
  #       - asset: fonts/TrajanPro.ttf
  #       - asset: fonts/TrajanPro_Bold.ttf
  #         weight: 700
  #
  # For details regarding fonts from package dependencies,
  # see https://flutter.dev/custom-fonts/#from-packages

Flutter doctor Run flutter doctor and paste the output below:

[βœ“] Flutter (Channel v1.12.13-hotfixes, v1.12.13+hotfix.9, on Mac OS X 10.15.4 19E287, locale en-VN)
    β€’ Flutter version 1.12.13+hotfix.9 at /Users/hoanganhtuan/development/flutter
    β€’ Framework revision f139b11009 (9 weeks ago), 2020-03-30 13:57:30 -0700
    β€’ Engine revision af51afceb8
    β€’ Dart version 2.7.2

 
[βœ“] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
    β€’ Android SDK at /Users/hoanganhtuan/Library/Android/sdk
    β€’ Android NDK location not configured (optional; useful for native profiling support)
    β€’ Platform android-R, build-tools 29.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_242-release-1644-b3-6222593)
    β€’ All Android licenses accepted.

[βœ“] Xcode - develop for iOS and macOS (Xcode 11.4.1)
    β€’ Xcode at /Applications/Xcode.app/Contents/Developer
    β€’ Xcode 11.4.1, Build version 11E503a
    β€’ CocoaPods version 1.9.1

[βœ“] Android Studio (version 4.0)
    β€’ Android Studio at /Applications/Android Studio.app/Contents
    β€’ Flutter plugin version 46.0.2
    β€’ Dart plugin version 193.7361
    β€’ Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)

[βœ“] VS Code (version 1.45.1)
    β€’ VS Code at /Applications/Visual Studio Code.app/Contents
    β€’ Flutter extension version 3.10.2

[βœ“] Connected device (4 available)
    β€’ Nokia 7 plus              β€’ B2NGAA8830704049                         β€’ android-arm64 β€’ Android 10 (API 29)
    β€’ Android SDK built for x86 β€’ emulator-5554                            β€’ android-x86   β€’ Android 10 (API 29) (emulator)
    β€’ TuanHA’s iPhone X         β€’ c938992824b3503c5d9daff372c9bb4644d4b330 β€’ ios           β€’ iOS 13.4.1
    β€’ iPhone 11                 β€’ 91E970E4-89D5-41D9-9FEC-C281D4FD6B66     β€’ ios           β€’ com.apple.CoreSimulator.SimRuntime.iOS-13-4 (simulator)

tuanha2000vn avatar May 30 '20 22:05 tuanha2000vn

Ok, I think I've fixed it.

These are the change make iOS release mode work again:

  1. Info.plist
    <key>FirebaseAppDelegateProxyEnabled</key>
    <false/>

Change to

    <key>FirebaseAppDelegateProxyEnabled</key>
    <string>NO</string>
  1. pubspec.yaml
firebase_messaging: ^6.0.16

Change to

firebase_messaging: 6.0.15

These change are against official document but I don't know why it work but hey it work!

tuanha2000vn avatar Jun 01 '20 02:06 tuanha2000vn

I am having the same problem but the suggestion didn't help. I also followed below: https://github.com/FirebaseExtended/flutterfire/issues/1041 didn't solve my issue too..

LiveRock avatar Jun 01 '20 07:06 LiveRock

I am having the same problem but the suggestion didn't help. I also followed below: #1041 didn't solve my issue too..

https://www.youtube.com/watch?v=9zWs0I7UpcQ ? it works for my

ushieru avatar Jun 05 '20 21:06 ushieru

This is real! Push notification works fine in debug mode but doesn't work if the app is in release mode. I get the same InvalidRegistration error when I send notification on token received in release mode. However, it works just fine for the token received in debug mode. I am using firebase_messaging: ^7.0.0

sam0829 avatar Oct 01 '20 08:10 sam0829

Try to add application.registerForRemoteNotifications() in your AppDelegate.swift. It worked for me. ver 7.0.0

maksym-ostrovyj-ew avatar Oct 23 '20 09:10 maksym-ostrovyj-ew

Try to add application.registerForRemoteNotifications() in your AppDelegate.swift. It worked for me. ver 7.0.0

It doesn't work for me. ver 7.0.3

rimidalv avatar Nov 11 '20 06:11 rimidalv

This definitely worked for me.

 <key>FirebaseAppDelegateProxyEnabled</key>
 <string>0</string>

devmoonho avatar Nov 11 '20 12:11 devmoonho

This definitely worked for me.

 <key>FirebaseAppDelegateProxyEnabled</key>
 <string>0</string>

it doesn't work for me ver 7.0.3, in ios 13.7. onMessage did not call with release mode. Have any other solution?

kunkaamd avatar Nov 18 '20 02:11 kunkaamd

I have fixed that by using APNs key. maybe I have a mistake in config production APNs Certificates.

kunkaamd avatar Nov 18 '20 07:11 kunkaamd

This worked for me when running on iOS14 and Xcode 12.1 on release/profile mode. Prior, it was only working in debug mode on my device. As mentioned in previous comments, I did the following.... 1. Switched my firebase_messaging package from 7.0.3 to 7.0.0 2. I then changed this in my Info.plist - <key>FirebaseAppDelegateProxyEnabled</key> <false/> to <key>FirebaseAppDelegateProxyEnabled</key> <string>0</string>

Hopefully this helps!

Andrew-Tolentino avatar Nov 22 '20 01:11 Andrew-Tolentino

I tried this @Andrew-Tolentino. Didn't work. If I donot change my info.plist I get the notification when the app is closed but not when it's open. I check it by adding a toast in onMessage and onResume. If I add this in my info.plist I donot get notifications at all.

But everything works fine on emulator or on physical device in debug mode. when I create a build for development and distribution it doesn't work.

muzammil22 avatar Nov 22 '20 18:11 muzammil22

This worked for me when running on iOS14 and Xcode 12.1 on release/profile mode. Prior, it was only working in debug mode on my device. As mentioned in previous comments, I did the following....

  1. Switched my firebase_messaging package from 7.0.3 to 7.0.0
  2. I then changed this in my Info.plist - <key>FirebaseAppDelegateProxyEnabled</key> <false/> to <key>FirebaseAppDelegateProxyEnabled</key> <string>0</string>

Hopefully this helps!

Lifesaver, spent last 4 hours trying to find the issue. This worked for me.

varundroid avatar Nov 28 '20 08:11 varundroid

@varundroid Hi. Were you able to receive notification on ios while the app is running ? I tried adding a toast message in onMessage method to see if the app receives notifications while in foreground. I see the toast message when I run the app on simulator but if I create a build and run on my physical device it doesn't show.

I have already tried the above mentioned fix.

muzammil22 avatar Dec 02 '20 09:12 muzammil22

This worked for me when running on iOS14 and Xcode 12.1 on release/profile mode. Prior, it was only working in debug mode on my device. As mentioned in previous comments, I did the following....

  1. Switched my firebase_messaging package from 7.0.3 to 7.0.0
  2. I then changed this in my Info.plist - <key>FirebaseAppDelegateProxyEnabled</key> <false/> to <key>FirebaseAppDelegateProxyEnabled</key> <string>0</string>

Hopefully this helps!

On ios 14.2 | i switch my firebase_messaging 7.0.3 to 7.0.0 debug mode is work but on release mode don't work :(

dua8racer avatar Dec 09 '20 05:12 dua8racer

This is the solution guys: FirebaseAppDelegateProxyEnabled Change in release mode: FirebaseAppDelegateProxyEnabled 0

kadnan0900 avatar Dec 09 '20 11:12 kadnan0900

I have the same kind of problem with a slight difference. In Profile and Debug mode it works perfectly. In Release mode I start the app, get the fcm token then put the app in the background or close it completely and send a push notification (via the Firebase console or Postman) nothing happens. After that I close the app (if it was just in the background) and open it again then put it in the background or close it again and send a push notification it works just fine. I have no idea what's going on. Also it works perfectly in every case on Android. Right now I'm testing it on an iPhone X with iOS 14.2 but we tried it with an iPhone 6 with iOS 12.4 and with an iPhone 11 Pro with 14.2. In every case the same things happened that I mentioned above. Does anybody have this problem? Or simply just doesn't get the notifications in Release mode no matter what?

csbence10 avatar Dec 09 '20 12:12 csbence10

I have the same problem as @csbence10 , just do not know what happens here. Close the app one time and open it again and it working.

hungtran2492 avatar Dec 19 '20 10:12 hungtran2492

I have the same problem as @csbence10 , just do not know what happens here. Close the app one time and open it again and it working.

@hungtran2492 Having same issue. I have tried to last week. But i can't find any solution. Do you find any solution?

dimple3695 avatar Dec 31 '20 09:12 dimple3695

I have the same kind of problem with a slight difference. In Profile and Debug mode it works perfectly. In Release mode I start the app, get the fcm token then put the app in the background or close it completely and send a push notification (via the Firebase console or Postman) nothing happens. After that I close the app (if it was just in the background) and open it again then put it in the background or close it again and send a push notification it works just fine. I have no idea what's going on. Also it works perfectly in every case on Android. Right now I'm testing it on an iPhone X with iOS 14.2 but we tried it with an iPhone 6 with iOS 12.4 and with an iPhone 11 Pro with 14.2. In every case the same things happened that I mentioned above. Does anybody have this problem? Or simply just doesn't get the notifications in Release mode no matter what?

@csbence10 Have you find any solution? Please let me know. I have tried to last many days.

dimple3695 avatar Dec 31 '20 09:12 dimple3695

@dimple3695 Not yet. However I started using the 8.0.0-dev.11 version of the package and it works fine on iOS but currently there's a little problem with Android. I created an issue, you can read about it more here It got merged, but there's no new release yet.

csbence10 avatar Jan 06 '21 09:01 csbence10