Skip to content

🐛 [firebase_messaging] iOS Notifications not received in 8.0.0-dev.8 #4097

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
paynekw opened this issue Nov 11, 2020 · 53 comments · Fixed by #4657
Closed

🐛 [firebase_messaging] iOS Notifications not received in 8.0.0-dev.8 #4097

paynekw opened this issue Nov 11, 2020 · 53 comments · Fixed by #4657
Assignees
Labels
impact: crowd Affects many people, though not necessarily a specific customer with an assigned label. (P2) plugin: messaging type: bug Something isn't working

Comments

@paynekw
Copy link

paynekw commented Nov 11, 2020

Bug report

Describe the bug

After upgrading to 8.0.0-dev.8 from 7.0.3, iOS does not receive/respond to push notifications i.e. no handlers or events fire. With 7.0.3, foreground notifications were working but not background notifications, which is the reason for upgrading to 8.x.

Android is fine whether in foreground or background, or terminated. Trace information from iOS shows that initialization succeeds without error. The iOS trace is the same as that from Android and shows no irregularities. iOS Requests permission, which I grant. Settings reports that all permissions are granted as expected.

I'm using an iPhone 6 physical device running iOS 12.4.9 and the flutter_local_notifications plugin. APNs is configured with a .p8 Authentication Key. When I send a notification via FCM to the iPhone, the response reports success with success: 1, failure: 0 and a valid message_id.

Steps to reproduce

Steps to reproduce the behavior:

  1. Install and configure the firebase_messaging: ^8.0.0-dev.8 plugin as per documentation and examples.
  2. Send a push notification to an iPhone via FCM.

Expected behavior

One of [FirebaseMessaging.onMessage, FirebaseMessaging.onBackgroundMessage, FirebaseMessaging.onMessageOpenedApp] should fire. I've added trace information to each handler and it appears that they are never invoked on iOS. As mentioned earlier, all work as expected in Android.


Additional context

AppDelegate.swift includes:

    if #available(iOS 10.0, *) {
      UNUserNotificationCenter.current().delegate = self as UNUserNotificationCenterDelegate
    }

Info.plist includes:

    <key>FirebaseAppDelegateProxyEnabled</key>
    <false/>
    <key>UIBackgroundModes</key>
    <array>
        <string>fetch</string>
        <string>processing</string>
        <string>remote-notification</string>
    </array>

I have tried various things to enable/disable method swizzling and also with/without the entry in info.plist. The setting appears to have no effect.

project.pbxproj includes:

/* Begin PBXProject section */
		97C146E61CF9000F007C117D /* Project object */ = {
			isa = PBXProject;
			attributes = {
				LastUpgradeCheck = 1020;
				ORGANIZATIONNAME = "**************";
				TargetAttributes = {
					97C146ED1CF9000F007C117D = {
						CreatedOnToolsVersion = 7.3.1;
						DevelopmentTeam = **********;
						LastSwiftMigration = 1100;
						SystemCapabilities = {
							com.apple.BackgroundModes = {
								enabled = 1;
							};
							com.apple.Push = {
								enabled = 1;
							};
						};
					};
				};

I believe I do not require an entitlements file with CODE_SIGN_ENTITLEMENTS pointing to it to specify the aps-environment, because FCM is configured with a .p8 key and not environment-specific certificates.

Sending notifications

I have tried with/without and all possible values for priority and content-available when sending the notification via FCM without any observable change in behavior.


Flutter doctor

Run flutter doctor and paste the output below:

Click To Expand
[√] Flutter (Channel stable, 1.22.3, on Microsoft Windows [Version 10.0.19041.610], locale en-GI)
    • Flutter version 1.22.3 at ...
    • Framework revision 8874f21e79 (13 days ago), 2020-10-29 14:14:35 -0700
    • Engine revision a1440ca392
    • Dart version 2.10.3

[√] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
    • Android SDK at ...
    • Platform android-30, build-tools 30.0.2
    • Java binary at: ...
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
    • All Android licenses accepted.

[√] Android Studio (version 3.6)
    • Android Studio at ...
    • Flutter plugin version 46.0.1
    • Dart plugin version 192.8052
    • Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b04)

[!] Android Studio (version 4.1.0)
    • Android Studio at ...
    X Flutter plugin not installed; this adds Flutter specific functionality.
    X Dart plugin not installed; this adds Dart specific functionality.
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)

[√] Connected device (1 available)
    • Android SDK built for x86 (mobile) • emulator-5554 • android-x86 • Android 10 (API 29) (emulator)

! Doctor found issues in 1 category.

I run multiple versions of Android Studio side-by-side, so ignore the incorrect warnings about the Dart and Flutter plugins not being installed in 4.x (they most certainly are.)


Flutter dependencies

Run flutter pub deps -- --style=compact and paste the output below:

Click To Expand
dependencies:
- bcv_domain 0.0.0 [bcv_global intl decimal]
- bcv_global 0.0.0 [intl decimal uuid]
- carousel_slider 2.3.1 [flutter]
- charts_flutter 0.9.0 [charts_common collection flutter intl logging meta]
- contacts_service 0.4.6 [flutter collection quiver]
- decimal 0.3.5 [rational]
- file_picker 2.0.0 [flutter flutter_web_plugins flutter_plugin_android_lifecycle plugin_platform_interface]
- firebase_core 0.5.2 [firebase_core_platform_interface flutter quiver meta firebase_core_web]
- firebase_messaging 8.0.0-dev.8 [meta flutter firebase_core firebase_core_platform_interface firebase_messaging_platform_interface]
- flutter 0.0.0 [characters collection meta typed_data vector_math sky_engine]
- flutter_local_notifications 3.0.1+2 [flutter platform flutter_local_notifications_platform_interface timezone]
- geolocator 6.1.6 [flutter geolocator_platform_interface]
- google_sign_in 4.5.6 [google_sign_in_platform_interface flutter meta google_sign_in_web]
- http 0.12.2 [http_parser path pedantic]
- image_picker 0.6.7+14 [flutter flutter_plugin_android_lifecycle image_picker_platform_interface]
- intl 0.16.1 [path]
- numberpicker 1.2.1 [flutter infinite_listview]
- package_info 0.4.3+2 [flutter]
- permission_handler 5.0.1+1 [flutter meta permission_handler_platform_interface]
- photo_view 0.10.2 [flutter]
- qr_flutter 3.2.0 [flutter qr]
- shared_preferences 0.5.12+4 [meta flutter shared_preferences_platform_interface shared_preferences_linux shared_preferences_macos shared_preferences_web shared_preferences_windows]
- validators 2.0.1 [vin_decoder]
- wc_flutter_share 0.2.2 [flutter path_provider]

dev dependencies:
- flutter_launcher_icons 0.7.5 [image args yaml]
- 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]
- pedantic 1.9.2 [meta]

transitive dependencies:
- archive 2.0.13 [crypto args path]
- args 1.6.0
- asn1lib 0.6.5
- async 2.5.0-nullsafety.1 [collection]
- basic_utils 2.6.3 [http logging json_annotation pointycastle asn1lib convert crypto]
- boolean_selector 2.1.0-nullsafety.1 [source_span string_scanner]
- characters 1.1.0-nullsafety.3
- charcode 1.2.0-nullsafety.1
- charts_common 0.9.0 [collection intl logging meta vector_math]
- clock 1.1.0-nullsafety.1
- collection 1.15.0-nullsafety.3
- convert 2.1.1 [charcode typed_data]
- crypto 2.1.5 [collection convert typed_data]
- fake_async 1.2.0-nullsafety.1 [clock collection]
- ffi 0.1.3
- file 5.2.1 [intl meta path]
- firebase_core_platform_interface 2.0.0 [flutter meta plugin_platform_interface quiver]
- firebase_core_web 0.2.1 [firebase_core_platform_interface flutter flutter_web_plugins meta js]
- firebase_messaging_platform_interface 1.0.0-dev.5 [flutter meta firebase_core plugin_platform_interface]
- flutter_local_notifications_platform_interface 2.0.0 [flutter plugin_platform_interface]
- flutter_plugin_android_lifecycle 1.0.11 [flutter]
- flutter_web_plugins 0.0.0 [flutter characters collection meta typed_data vector_math]
- geolocator_platform_interface 1.0.8 [flutter meta plugin_platform_interface vector_math]
- google_sign_in_platform_interface 1.1.2 [flutter meta quiver]
- google_sign_in_web 0.9.2 [google_sign_in_platform_interface flutter flutter_web_plugins meta js]
- http_parser 3.1.4 [charcode collection source_span string_scanner typed_data]
- image 2.1.18 [archive xml meta]
- image_picker_platform_interface 1.1.1 [flutter meta http plugin_platform_interface]
- infinite_listview 1.0.1+1 [flutter]
- js 0.6.2
- json_annotation 3.0.1
- logging 0.11.4
- matcher 0.12.10-nullsafety.1 [stack_trace]
- meta 1.3.0-nullsafety.3
- path 1.8.0-nullsafety.1
- path_provider 1.6.24 [flutter path_provider_platform_interface path_provider_macos path_provider_linux path_provider_windows]
- path_provider_linux 0.0.1+2 [path xdg_directories path_provider_platform_interface flutter]
- path_provider_macos 0.0.4+6 [flutter]
- path_provider_platform_interface 1.0.4 [flutter meta platform plugin_platform_interface]
- path_provider_windows 0.0.4+3 [path_provider_platform_interface meta path flutter ffi win32]
- permission_handler_platform_interface 2.0.1 [flutter meta plugin_platform_interface]
- petitparser 3.1.0 [meta]
- platform 2.2.1
- plugin_platform_interface 1.0.3 [meta]
- pointycastle 1.0.2
- process 3.0.13 [file intl meta path platform]
- qr 1.3.0 [meta]
- quiver 2.1.5 [matcher meta]
- random_string 2.1.0
- rational 0.3.8
- shared_preferences_linux 0.0.2+4 [file flutter meta path path_provider_linux shared_preferences_platform_interface]
- shared_preferences_macos 0.0.1+11 [shared_preferences_platform_interface flutter]
- shared_preferences_platform_interface 1.0.4 [meta flutter]
- shared_preferences_web 0.1.2+7 [shared_preferences_platform_interface flutter flutter_web_plugins meta]
- shared_preferences_windows 0.0.1+3 [shared_preferences_platform_interface flutter ffi file meta path path_provider_platform_interface path_provider_windows]
- sky_engine 0.0.99
- source_span 1.8.0-nullsafety.2 [charcode collection path term_glyph]
- stack_trace 1.10.0-nullsafety.1 [path]
- stream_channel 2.1.0-nullsafety.1 [async]
- string_scanner 1.1.0-nullsafety.1 [charcode source_span]
- term_glyph 1.2.0-nullsafety.1
- test_api 0.2.19-nullsafety.2 [async boolean_selector collection meta path source_span stack_trace stream_channel string_scanner term_glyph matcher]
- timezone 0.5.9 [path]
- typed_data 1.3.0-nullsafety.3 [collection]
- uuid 2.2.2 [crypto convert]
- vector_math 2.1.0-nullsafety.3
- vin_decoder 0.1.2 [meta basic_utils http random_string]
- win32 1.7.3 [ffi]
- xdg_directories 0.1.2 [meta path process]
- xml 4.5.1 [collection convert meta petitparser]
- yaml 2.2.1 [charcode collection string_scanner source_span]

The frustrating part is that I do not have XCode or a Mac. Each cloud build takes around 20 minutes, and costs money. I haven't ruled out the possibility of the XCode project configuration being slightly incomplete/incorrect due to not having access to XCode, however I have tried everything I can think of, and have run out of resources providing hints as to what the problem might be.

So far, two full days have been spent trying to get this to work.

@paynekw paynekw added Needs Attention This issue needs maintainer attention. type: bug Something isn't working labels Nov 11, 2020
@Haldlugal
Copy link

Hello!
There is a problem with typization when creating a RemoteMessage from data that is received from push notification on ios. data argument should be <String, dynamic>, not <String, String>, as I understand.
For example, that is data that I receive in my Push on Ios: data: {fcm_options: {image: https://images-na.ssl-images-amazon.com/images/I/81-yKbVND-L._SY355_.png}, test: test}
Flutter don't like such typization and throws an Error that isn't handled anywhere.

@markusaksli-nc
Copy link
Contributor

I can't reproduce this with just the official example on firebase_messaging: ^8.0.0-dev.8 on the latest flutter master 1.24.0-8.0.pre.208.

flutter doctor -v
[✓] Flutter (Channel master, 1.24.0-8.0.pre.208, on Mac OS X 10.15.7 19H2 darwin-x64, locale en-GB)
    • Flutter version 1.24.0-8.0.pre.208 at /Users/markus/development/flutter_master
    • Framework revision 15d2d8a875 (8 hours ago), 2020-11-11 20:04:03 -0500
    • Engine revision d97a81c889
    • Dart version 2.12.0 (build 2.12.0-31.0.dev)

[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.1)
    • Android SDK at /Users/markus/Library/Android/sdk
    • Platform android-30, build-tools 30.0.1
    • Java binary at: /Users/markus/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/201.6858069/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 12.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 12.1, Build version 12A7403
    • CocoaPods version 1.10.0

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 4.1)
    • Android Studio at /Users/markus/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/201.6858069/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      � https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      � https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)

[✓] Connected device (5 available)
    • Nevercode’s iPhone (mobile) • b668e524315069f3db3661ac11ff1f66afafebdb • ios            • iOS 14.1
    • iPhone 12 Pro Max (mobile)  • 1C7EE787-1EC9-427C-AFEE-224EF736BBCA     • ios            • com.apple.CoreSimulator.SimRuntime.iOS-14-1 (simulator)
    • macOS (desktop)             • macos                                    • darwin-x64     • Mac OS X 10.15.7 19H2 darwin-x64
    • Web Server (web)            • web-server                               • web-javascript • Flutter Tools
    • Chrome (web)                • chrome                                   • web-javascript • Google Chrome 86.0.4240.193
    ! Error: Nevercode’s iPhone is busy: Copying cache files from device. Xcode will continue when Nevercode’s iPhone is finished. (code -10)

• No issues found!

Everything works fine on both Android and iOS. From the sounds of it it could be an Xcode config issue. The official steps for configuring the Xcode project and APN is at FCM via APNs Integration.

Have you followed these steps? I wouldn't expect notifications to work without this.

@markusaksli-nc markusaksli-nc added blocked: customer-response Waiting for customer response, e.g. more information was requested. and removed Needs Attention This issue needs maintainer attention. labels Nov 12, 2020
@paynekw
Copy link
Author

paynekw commented Nov 12, 2020

@markusaksli-nc I followed the configuration steps carefully, and as mentioned in the bug report iOS notifications were working great in version 7.0.3.

After migrating to ^8.0.0-dev.8 iOS went completely dead without any changes to the XCode, Apple, or FCM configuration, so although I said I haven't completely ruled out XCode configuration, I am reluctant to believe that it's a configuration issue.

Firebase reports success when sending a notification. If there's a problem it typically responds with failure and a reason e.g. "not registered", "authentication error", etc.

Can you confirm that it all works on Flutter stable channel, as I saw you tested against master?

@google-oss-bot google-oss-bot added Needs Attention This issue needs maintainer attention. and removed blocked: customer-response Waiting for customer response, e.g. more information was requested. labels Nov 12, 2020
@markusaksli-nc
Copy link
Contributor

It works on stable as well for me.

If the notifications reach the device but the callbacks are not triggered, could you try to see if there is any useful output with flutter run -v or in Xcode console?

@markusaksli-nc markusaksli-nc added blocked: customer-response Waiting for customer response, e.g. more information was requested. and removed Needs Attention This issue needs maintainer attention. labels Nov 12, 2020
@paynekw
Copy link
Author

paynekw commented Nov 12, 2020

Thank you for testing on stable channel.

I needed a sanity check to ensure that something on the Apple/Firebase side hadn't changed or gone foul, so I went back to using package 7.0.3 and once again I am receiving notifications on iOS.

I don't have a Mac with XCode, and so cannot get closer to the internal logs or output. What I did was embed debug code everywhere to emit trace information to a REST API for logging. The trace tells me that either the device isn't receiving notifications (unlikely, because using 7.0.3 they are received) or the callbacks aren't being fired (trace shows nothing whatsoever emitted when using 8.x).

I see everything initialize OK and without error. Both devices register with Firebase, because the notification sends OK. If the device didn't register, the error message in the response is NotRegistered.

Something's gone a bit wack somewhere on the iOS side I think, that isn't causing a problem in your canonical example. I'm unclear as to whether the delegate assignment in AppDelegate.swift is still needed (8.x change log says no, then yes, then maybe no).

Perhaps the previous issue with co-existing with other plugins e.g. flutter_local_notifications has resurfaced.

I don't really know what to try next.

@google-oss-bot google-oss-bot added Needs Attention This issue needs maintainer attention. and removed blocked: customer-response Waiting for customer response, e.g. more information was requested. labels Nov 12, 2020
@den-ree
Copy link

den-ree commented Nov 12, 2020

Have the same problem on iOS

@diegogarciar
Copy link
Contributor

On my side its not working when including the content-available flag, I think the didReceiveRemoteNotification its not sending the message to flutter

@paynekw
Copy link
Author

paynekw commented Nov 12, 2020

Everyone, please share the iOS version running on your phones. I believe this issue may be iOS version-specific. In #4096 it's working on 14.2.

From what I have read, didReceiveRemoteNotification is legacy support for versions < 10.

The documentation for content-available is misleading. In some places I've read that content-available is to force a silent, background-only message, so that app can update its content in the background. The package documentation states that content-available: true will force a high-priority notification. Nowhere does it say whether the value should be a bool or a string.

@den-ree
Copy link

den-ree commented Nov 12, 2020

@paynekw I was using iOS 14.1, now updating to iOS 14.2. I will do testing and return back with results.

@diegogarciar
Copy link
Contributor

same as @den-ree I might wait for Xcode 12.2 official release though. @paynekw I normally use "content-available" : 1 and it works.

I mentioned about didReceiveRemoteNotification as I debugged this in the code

 if (notification.request.content.userInfo[@"gcm.message_id"]) {
    NSDictionary *notificationDict =
        [FLTFirebaseMessagingPlugin NSDictionaryFromUNNotification:notification];

    // Don't send an event if contentAvailable is true - application:didReceiveRemoteNotification
    // will send the event for us, we don't want to duplicate them.
    if (!notificationDict[@"contentAvailable"]) {
      [_channel invokeMethod:@"Messaging#onMessage" arguments:notificationDict];
    }
  }

So I was seeing how the last line was working but skipped when I included content-available, didReceiveRemoteNotification was never called when adding content-available.

@furkankurt
Copy link

Same problem here, on iOS 14.2 I cannot receive the notifications at all.

@diegoveloper
Copy link
Contributor

I'm on iOS 13.5.2, push notifications with notification payload are received but I'm not receiving push without the payload. I want to receive silent notifications but it doesn't work, I'm testing from console.

DATA='{"content-available": true, "data": {"badge": 10, "click_action": "FLUTTER_NOTIFICATION_CLICK", "id": "34331"}, "to": "my_token"}'
curl https://fcm.googleapis.com/fcm/send -H "Content-Type:application/json" -X POST -d "$DATA" -H "Authorization: key=my_key" -H "apns-push-type: background"

anything wrong?

@markusaksli-nc
Copy link
Contributor

I updated to iOS 14.2 on my physical and Xcode to 12.2, and prefromed a fresh install but notifications still work as expected with the official example on 1.24.0-8.0.pre.229 with

  firebase_core: ^0.5.2
  firebase_messaging: ^8.0.0-dev.8
  flutter_local_notifications: ^3.0.1+2
  http: ^0.12.2
flutter doctor -v
[✓] Flutter (Channel master, 1.24.0-8.0.pre.229, on Mac OS X 10.15.7 19H2 darwin-x64, locale en-GB)
    • Flutter version 1.24.0-8.0.pre.229 at /Users/markus/development/flutter_master
    • Framework revision 7cda6866b0 (10 hours ago), 2020-11-12 22:39:02 -0500
    • Engine revision dddb532b5c
    • Dart version 2.12.0 (build 2.12.0-37.0.dev)

[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.1)
    • Android SDK at /Users/markus/Library/Android/sdk
    • Platform android-30, build-tools 30.0.1
    • Java binary at: /Users/markus/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/201.6858069/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 12.2)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 12.2, Build version 12B45b
    • CocoaPods version 1.10.0

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 4.1)
    • Android Studio at /Users/markus/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/201.6858069/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      � https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      � https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)

[✓] Connected device (4 available)
    • Nevercode’s iPhone (mobile) • b668e524315069f3db3661ac11ff1f66afafebdb • ios            • iOS 14.2
    • macOS (desktop)             • macos                                    • darwin-x64     • Mac OS X 10.15.7 19H2 darwin-x64
    • Web Server (web)            • web-server                               • web-javascript • Flutter Tools
    • Chrome (web)                • chrome                                   • web-javascript • Google Chrome 86.0.4240.193

• No issues found!

I'm going to label this issue anyway due to the amount of comments but everybody please make sure you have followed FCM via APNs Integration closely.

@markusaksli-nc markusaksli-nc added plugin: messaging and removed Needs Attention This issue needs maintainer attention. labels Nov 13, 2020
@diegoveloper
Copy link
Contributor

@markusaksli-nc did you try with silent notifications?

@markusaksli-nc
Copy link
Contributor

@diegoveloper Works for me

Payload
{
  "content_available": true,
  "data": {
    "badge": 10,
    "click_action": "FLUTTER_NOTIFICATION_CLICK",
    "id": 34331
  },
  "to": "<FCM Token>"
}
curl https://fcm.googleapis.com/fcm/send -H "Content-Type:application/json" -X POST -d @send.json -H "Authorization: key=<key>"
flutter: {messageId: 1605277313184085, data: {id: 34331, badge: 10, click_action: FLUTTER_NOTIFICATION_CLICK}, contentAvailable: true}
flutter: Handling a background message 1605277151756920

@diegoveloper
Copy link
Contributor

diegoveloper commented Nov 13, 2020

@markusaksli-nc ah wait, content_available vs content-available , I was checking the documentation from: https://firebase.flutter.dev/docs/messaging/usage/ , is the doc wrong ?

Screen Shot 2020-11-13 at 9 28 49 AM

btw I'm talking about silent pushes in iOS

@markusaksli-nc
Copy link
Contributor

It isn't wrong since it is the name of the APN payload parameter, that guide is more for the dart code usage of the flutter plugin.

I'd refer to the official FCM HTTP Ref for sending notifications through FCM.

content_available | Optional, boolean | On iOS, use this field to represent content-available in the APNs payload.

@diegoveloper
Copy link
Contributor

@markusaksli-nc okay, did you try silent push in iOS?

@markusaksli-nc
Copy link
Contributor

dev.9 seems to have fixed the issues for me, receiving everything properly again.

@paynekw
Copy link
Author

paynekw commented Nov 27, 2020

I'm releasing a build today and will report findings using dev.9 soon

@diegogarciar
Copy link
Contributor

diegogarciar commented Nov 27, 2020

Heres what I tested out for dev.9

"content-available": 0
Background: Notification shows
Foreground: onMessage gets called
summary: working as expected

"content-available": 1
Background: Notifications shows, onBackgroundMessage not called
Foreground: onMessage is not called
summary: flutter is completely dead when using content-available

btw, firebase.flutter.dev docs are incorrect in this example

 apns: {
      payload: {
        aps: {
          contentAvailable: true,
          sound: 'default',
        },
      },
    },

it is not contentAvailable, it is content-available as per apple's documentation

so if you're trying with contentAvailable, you are receiving a normal notification and that's why its working

@paynekw
Copy link
Author

paynekw commented Nov 27, 2020

I'm afraid to say that iOS is still completely dead for me on dev.9

@markusaksli-nc markusaksli-nc added the impact: crowd Affects many people, though not necessarily a specific customer with an assigned label. (P2) label Nov 30, 2020
@paynekw
Copy link
Author

paynekw commented Dec 4, 2020

I have a few things on my mind.

  1. When looking at and following the instructions here, the screen cast clearly shows uploading of a .p8 key and the absence of APNs environment-specific certificates. According to the instructions, a .p8 key being uploaded is all that is required - it's apparently APNs environment-agnostic.

  2. When looking at the example project, I see that it enforces code signing an .entitlements file to specify the aps-environment.

  3. When I do the same and sign an .entitlements file, but without having environment-specific certificates configured, the build succeeds, but I get a runtime error when sending a notification, and the error is InvalidCredential, which is expected, as I have not configured a certificate for the designated environment.

  4. Therefore, as I understand it, a .p8 key and code-signing environment-specific certificates are mutually exclusive. You either use a .p8 key, or you code-sign an .entitlements file pointing to a certificate, specific to the environment specified in the .entitlements file.

Questions:

  1. If the instructions demonstrate that all that is required is to use a .p8 key, but the example project is signing an .entitlements file, and .p8 and .entitlements appear to be mutually exclusive, what is the example app actually using?

AFAIK there's no way to upload a .p8 and also configure environment-specific certificates in Firebase Messaging. I might be wrong, but I tried and it appears to be either one or the other.

TL;DR

I don't understand (forgive me) how the example project can be configured as per the instructions to use a .p8 key only, and also work with a code-signed .entitlements file, unless somehow in the past someone loaded APNs certificates or something locally into Xcode which is overriding the general configuration.

I'd like to see this tested being built in the Cloud and not just locally.

EDIT: I never receive InvalidCredential with my current setup using .p8.

@Salakar
Copy link
Member

Salakar commented Dec 6, 2020

it is not contentAvailable, it is content-available as per apple's documentation

so if you're trying with contentAvailable, you are receiving a normal notification and that's why its working

This is not correct. contentAvailable in that example IS correct - this is the TypeScript/JS name defined in the Firebase Admin SDK for Node.js. It's not the APNS http api name. https://github.com/firebase/firebase-admin-node/blob/master/src/messaging/index.ts#L331

@Salakar
Copy link
Member

Salakar commented Dec 6, 2020

  1. If the instructions demonstrate that all that is required is to use a .p8 key, but the example project is signing an .entitlements file, and .p8 and .entitlements appear to be mutually exclusive, what is the example app actually using?

The .p8 is for server code and is not for Xcode and has no direct relation to the entitlements / profile for Xcode in this context.

Specifying the Team ID on the Firebase Console when uploading the .p8 is how the two can be connected. The Firebase Console/backend can read provisioned profiles/app ids from an Apple API using the .p8 and based on your Firebase iOS Bundle Identifier (defined when creating your iOS app on the Firebase Console) pair this up with a provisioning profile that has the APNs entitlement where the App Id matches the Bundle ID.

@aytunch
Copy link

aytunch commented Dec 12, 2020

@diegogarciar were you able to get onBackgroundMessage callback to run in all cases? I am having problems with iOS. The operating systems shows a banner while app is in the background but onBackgroundMessage does not fire no matter what I send

@diegogarciar
Copy link
Contributor

@aytunch no, it seems that
optional func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void)

is still not being called when using contentAvailable. And that function is in charge of calling either onBackgroundMessage or onMessage based on background state.

@aytunch
Copy link

aytunch commented Dec 12, 2020

@diegogarciar thanks for the quick response. I understand that the problem is being caused by the native iOS code. Not from the Flutter side. However in my case I am sending a Data&Notification message, not an only Data message. So content-available should not be relevant for my case. onBackgroundMessage should fire automatically.
@Salakar Can you please confirm if this is a bug or not and fix the native side accordingly?

@diegogarciar
Copy link
Contributor

@aytunch onBackgroundMessage is sent to flutter only from that iOS function, so if that function is not working, it will fail for all message types.

PD: I'm also using Data&Notification message.

@carlos-labrador
Copy link

I have the same issue with silent message (only with "data")
Finally, i juste change contentAvailable: true by content_available: true and now my silent message works great again !

It works for me, thanks.

@vanlooverenkoen
Copy link

vanlooverenkoen commented Jan 6, 2021

I am not receiving push notifications on my iOS simulators. starting from 8.x.x
In 7.0.3 I was able to receive push notifications when the app was open. when the app is closed no push notifications will be received as expected. But after upgrading to 8.x.x I am not receiving any push notifications on my iOS simulators. Real device works fine.

Why is this changed in the new version?

After some testing I saw that my apns token was null on a simulator and not null on a real device. How is it possible that I received notification in the old version but not in the new release?

Right now I am using 8.0.0-dev.11

@paynekw
Copy link
Author

paynekw commented Jan 6, 2021

@vanlooverenkoen I believe the root cause was discovered in #4388, and we're now waiting on #4412. I seem to recall reading in the documentation that notifications don't work in simulator by default. There may be a way to test notifications in simulator, but I believe the default behavior is that they don't - a physical device is required.

@vanlooverenkoen
Copy link

@paynekw a physical device is indeed required if the app is killed so the notifications are shown in the notification tray. On 7.0.3 we were able to develop our app in the simulator with the notification updates. But only while the app was open. (as expected). If I switch back to version 7.0.3 the notifications still work. but we are required to upgrade to 8.x.x because of the v2 embedding for android. So you can already see the problem.

We cannot use v1 because we need the functionality of v2 for another part of our app.
and v2 is breaking the firebase_messaging op iOS

I saw that issue as well. But I am not using firebase_auth. We are only using firebase_core & firebase_messaging.

@paynekw
Copy link
Author

paynekw commented Jan 6, 2021

@vanlooverenkoen in that case, I'm sorry I can't answer your specific question. There appear to be many having a variety of issues in various situations with 8.x. I myself have been unable to receive notifications since the beginning of November.

@jamesblasco
Copy link
Contributor

I managed to solve this issue that was affected by the auth package. I am not having problems so far after this change
#4412 (comment)

@Salakar
Copy link
Member

Salakar commented Jan 13, 2021

In 7.0.3 I was able to receive push notifications when the app was open

On 7.0.3 we were able to develop our app in the simulator with the notification updates. But only while the app was open.

Yes correct as v7 used a now deprecated & removed feature from the underlying Firebase iOS SDK for messaging - a direct channel connection. The old Firebase iOS SDK could establish a direct connection to the FCM backend and receive messages bypassing the need for APNs whilst the app was open. This feature no longer exists, everything MUST now go through APNs - so you need to ensure you've set it up correctly.

I can't speak as to why it was removed but from my experience it's probably for the best, now you must setup APNs and if you don't do it correctly then you won't get any notifications, rather than the possibly confusing 'it works in the foreground but not in the background' issues (there's so many of these issues that have been made on FlutterFire and also over at React Native Firebase).

@paynekw
Copy link
Author

paynekw commented Jan 18, 2021

I don't know whether #4657 fixed everyone else's problems, but after updating packages and dependencies, following this migration guide, revisiting all setup & configuration instructions, examining change logs etc., iOS is still completely dead for me.

Test notifications from Firebase Console aren't received on iOS, and the (legacy) REST endpoint continues to report success with no delivery to the device.

I give up. Am going to find an alternative to FCM because this has been a nightmare.

Thank you to the maintainers and the community who have been helpful.

@diegogarciar
Copy link
Contributor

@paynekw if you’re receiving on android but not on iOS then its an iOS problem, not fcm. Changing product wont fix it unless you configure it correctly. Try sending notifications with the apns server itself first, once it works, check if with fcm works too

@paynekw
Copy link
Author

paynekw commented Jan 18, 2021

@diegogarciar agree wholeheartedly, thanks for the sound advice. Understand my frustration at this point...

@vanlooverenkoen
Copy link

@paynekw if you’re receiving on android but not on iOS then its an iOS problem, not fcm. Changing product wont fix it unless you configure it correctly. Try sending notifications with the apns server itself first, once it works, check if with fcm works too

We had a problem where our implemetation was working on android but not on iOS. Turns out that the php package we were using was causing the issue.

We removed the php package at backend side. And we are now using the rest api directly. @paynekw maybe you have a similar issue?

@firebase firebase locked and limited conversation to collaborators Feb 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
impact: crowd Affects many people, though not necessarily a specific customer with an assigned label. (P2) plugin: messaging type: bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.