-
Notifications
You must be signed in to change notification settings - Fork 4k
[firebase_messaging] iOS is not receiving apns payload and not showing notification when it is in background or killed #2854
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
Comments
same issues :(. Please help! |
you can set content_available and priority option |
I`m facing the same problem right now, I tried the same request and the problem persists. |
@whatamelon From apple, the content-available option is for:
I don't want a silent notification in background, I want a normal notification to show to the user. I need include "alert". |
I had the same issue. Pushes once worked but then randomly stopped working and I couldn't figure out why. Here is a decent blog post on how to debug FCM for iOS: https://firebase.googleblog.com/2017/01/debugging-firebase-cloud-messaging-on.html After following along I realized that my app was successfully getting the device token in I wish there was a way to be able to verify that your APNS token was in sync with your FCM token, but I assumed this could be the problem anyway. I found at that at some point I disabled Swizzling by adding this to my plist: <key>FirebaseAppDelegateProxyEnabled</key>
<false/> *Some people mentioned changing this bool to a string I did this because I needed to grab the This is outlined in the references here: import FirebaseMessaging
...
override func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
Mixpanel.mainInstance().people.addPushDeviceToken(deviceToken) //For Mixpanel purposes, not needed if not using
Messaging.messaging().apnsToken = deviceToken //*THIS WAS MISSING*
super.application(application, didRegisterForRemoteNotificationsWithDeviceToken: deviceToken) //Not sure if calling super is required, but did anyway
} I realized that if you disable swizzling you must set the APNS token manually or FCM will never know the device token meaning remote or background notifications will never come to the app. So simply adding this line into the Messaging.messaging().apnsToken = deviceToken Side note:If you disable swizzling, the FCM analytics won't automatically work (for deliveries and opens) so you'll have to add this code in to ensure FCM knows about it. This is outlined in the references here: override func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Swift.Void) {
Messaging.messaging().appDidReceiveMessage(userInfo)
///Not sure if calling super is required here
super.application(application, didReceiveRemoteNotification: userInfo, fetchCompletionHandler: completionHandler)
} |
@robrichardson13 Thanks for your solution, I did not realize that by disabling method swizzling I had to implement or call the functions that Firebase Message was handling in the background. In addition to the above, I would also emphasize that people call
|
Hi @robrichardson13 thank's for your reply. First, I didn't have So I added the override func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
let deviceTokenString = deviceToken.reduce("", {$0 + String(format: "%02X", $1)})
print("==== didRegisterForRemoteNotificationsWithDeviceToken ====")
print(deviceTokenString)
Messaging.messaging().apnsToken = deviceToken
} But after that, it happened exactly like before. The FCM can't deliver the notifications when the app is in background, only when it is in foreground. Also I tested sending from FCM directly to my device token (not using topics), I get the same result. I conclude that if the firebase can deliver notifications when app is in foreground, then it has the apn token registered successfully on its backend. @robrichardson13 Am I right about this conclusion? I didn't solve my problem yet. I know that APN is working because I tested on Pusher, but when it is sent from FCM it's not working. I am not sure if it's related to |
Hi everyone. Works in all situations on android but On launch and on resume do not trigger when app is in background or terminated. @robrichardson13 I tired your solution but it hasn't changed. Flutter doctor version
App Delegate.swift
Fcm code
Also Info.plist added
Firebase messagin version is 6.0.16. Is there an error in the code I wrote or is it in the fcm package? |
Your android folder should be a Application.java file import io.flutter.app.FlutterApplication; public class Application extends FlutterApplication implements PluginRegistry.PluginRegistrantCallback {
} |
We have been experiencing similar issue and thanks you my colleague @JanKn not upgrading the app on his iOS device, we realised that notifications worked on older builds. Trying various builds, I have come to the conclusion that the point it stopped working was when I upgraded my macOS to Catalina. I am tempted to downgrade to Mojave to see if that really was the cause. At present nothing I have tried has worked with current xcode / macOS to build the app |
@kmdinake You don't need to call
@FernandoUFS FCM notifications being received in the foreground does NOT mean that the APN token is registered successfully. My assumption is that FCM in the foreground uses some sort of Socket to deliver in the foreground and uses the iOS APNS (Remote Notifications) for background delivery. So if background delivery isnt working, I would assume it means that the APN token is never being sent to FCM correctly. @curlyeto try setting your <key>FirebaseAppDelegateProxyEnabled</key>
<false/> |
@robrichardson13 thanks for answering. I assigned a false value to FirebaseAppDelegateProxyEnabled. I am sending a notification from postman. When the application is open, response data type. When it is closed, reponse notificaiton type. Postman json
I want the data type from the data postman in the background. I've been dealing for 4 or 5 days and I couldn't solve the problem |
@curlyeto I have been running into a situation where if the code fails in the onMessage, onResume functions, that the application will not report the error. Is the error happening in an isolate? Could you try stripping down the sendNotifications function to just print to console? Also, I ended up using conditional logic around the message map using message.containsKey('data') etc. |
Hi guys, after doing everything, the notification worked again, I had a particular problem that I didn't notice.
I just added it again to the main project's pubspec.yml, also I did the same thing as @kmdinake and @robrichardson13 overriding those methods. Now firebase can deliver notifications in background. I didn't even remove the overrode code on iOS because it's working and tomorrow we will launch a new version. But it seems like the problem was just that. |
Hi guys, @mintymac thanks for your answer. On message, on resume funtions is working. I added showNotficaiton function inside print but not working in the backgorund. When I open the app when I send a notification in the background, the on message function works.
App Delegate.swift
Firebase request json
FirebaseAppDelegateProxyEnabled boolean false and string NO I tried two status but noting changing. I want the data type from the data postman in the background. What function is triggering in the background for ios ? Where am I doing wrong ? Firebase request json format it is correct ? Can you help me @FernandoUFS , @mintymac , @robrichardson13 ? |
Hey guys, I've been having the same issue. Since I was using flutter_local_notification package to display notifications, I had to set the value of FirebaseProxyEnabled to false, For that reason, firebase auth wasn't working properly, so I followed these steps:https://firebase.google.com/docs/auth/ios/phone-auth#appendix:-using-phone-sign-in-without-swizzling |
@curlyeto Of course, happy to. From my understanding, FirebaseMessaging delivers the data message in iOS via onMessage if the app is terminated. Is there something you can accompolish with in app messaging to fill the gap for Android? |
None of the proposed resolutions are working here, not sure what to try next. |
@mintymac I didn't understand this sentences. " Is there something you can accompolish with in app messaging to fill the gap for Android? " . Can you explain in detail? |
I can confirm that It's also working for me on TestFlight. |
How? |
Push is working fine for me on IOS using flutter, an APNs Authentication Key in the firebase console, and firebase_messaging: ^6.0.16 in my pubspec.yaml. I am not using TestFlight. I used the console on firebase / Compose notification / "send test message". With only "Notification title" and "Notification text" fields filled in and I'm getting push notifications with the app closed coming through. |
For Firebase Messaging setting up i followed the steps from https://pub.dev/packages/firebase_messaging And for local flutter notifications i followed the steps from https://pub.dev/packages/flutter_local_notifications Previously, for Android side, it was working fine for me. Notifications was showing up when app is on foreground and background. However, for iOS side, notifications only showing up when app is on foreground, it was not showing when app is on background. What i have done below has solved my problem. When sending firebase message payload, make sure the title and the body of the message is nested under ['notification'] instead of ['data'] (I'm using node.js to code my functions). You can add additional data under ['data'] My node js code
What i have done previously that didn't work for iOS background is i put my title and body in ['data']
After you have put your title and body under ['notification'], next go to your dart code (Setting up FCM part). When configuring FCM (The part where you initialize onMessage, onResume, onLaunch, onBackgroundMessage), make sure when your platform is iiOS, set onBackgroundMessage to null. Dart code
_My backgroundMessageHandler
Finally, under XCode, under the tab Signing & Capabilities, i have ticked the Automatically manage signing. (You should have already enabled your Background Mode, ticked Background Fetch and Remote Notifications as well as enabled Push Notification if you have followed the setup procedures in the links above). I hope these solutions help. It worked for me. |
This is what I experienced, the push message goes well when the app is running on the foreground, but not when it's on the background; both when using simulator or test device. |
This fixed it for me, however I still don't hear any sound on the phone... |
Hello guys! I'm having the same problem. On android everything works perfectly. In IOS, with the app in the foreground, notification messages trigger the onMessage callback, with the app in the background or closed, no notification is delivered to the IOS tray, but when opening the app, onMessage is triggered, as if the notification was being delivered at that time. I created a new project just to test notifications on IOS, in this new project the behavior was the same. Has anyone managed to find any solution? Any idea what is @TahaTesser? From what I see many people are facing this problem. |
I have the exact opposite issue. FCM works in the background but not in the foreground. We followed https://pub.dev/packages/firebase_messaging. |
My app is literally useless without pushes being sent to the user when backgrounded or stopped (personal location-aware safety alert app), and they worked in previous versions using the exact same code. This new version cleans up a lot of silly Flutter mistakes we made while learning Flutter 2 years ago because we were desperate to get off React Native. This new version structurally looks exactly like the old version in the main.dart and dependencies in the YAML file. Something got updated, now this thread applies 100%. (sigh) It's to the point where I'm dusting off the rev-1 product written in Swift to do a bunch of feature updates and push out because it works just fine using native APNS and 100% native code... which means we have to version freeze the Android version and React Native libraries. I don't know at this point if it's some deep dependency somewhere, a breakage in some updates to FCM, or what's going on, but I'm stuck, and really don't have any more time to put into tracking this down when 100 threads just like this all end with dozens of people still looking for an answer. (Note: FCM reports success on the push, so I am at a loss as to what to check next) |
holy crap. this worked. https://stackoverflow.com/questions/58198340/firebase-push-notifications-dont-work-on-ios-13 I did NOT expect that, and how can we control that without the user getting involved? Because that is simply NOT a scalable, viable solution. It simply isn't.
|
Maybe this helps. Running the app in XCode, I can see this response from the listener on the ios push notifications settings: However, the Flutter code CLEARLY asks for these settings to all be true.
Additionally, shouldn't that call to requestNotificationPermissions trigger the device's built-in dialog asking the user to approve notifications? I put it on one real device and a number of simulators I hadn't used before, and got no dialog. I assumed it was because I'd previously installed this bundle name on the various previous devices, even though I'd deleted it, but if it's not asking for perms even on new devices - even though notifications do get set up in settings - would that have something to do with what's going on? |
Might not be the solution to all the problems here but just in a case: For some reason, this refresh seems to happen less often on Android... Hope it helps PS : Thanks for the blog post @robrichardson13 it was very helpful (https://firebase.googleblog.com/2017/01/debugging-firebase-cloud-messaging-on.html) |
not receive notification in the ios simulator while the app in the background or kill. |
facing same problem. |
ya still facing the same problem, anyone can help ? 😕 |
Specifically replying to @anztrax as I totally sense and feel your frustration. terminated the project in Flutter for a variety of reasons, and wrote the iOS version in native code, and for the time being, I'm not offering an Android version of this particular project. For the other project where we already have an installed base, I have suspended updates, and rolled back a lot of commits to the version I knew last worked, and have frozen that version as "the" version for the time being. In my investigation, starting over from scratch on a brand new project, I can make things work and as the project progresses, there comes a point where lots of stuff stops working. I'm probably 5 or 6 redoes into this investigation, to the point that the only thing I've really learned is that lagging dependencies, weird dependency and/or version conflicts, etc., DO exist and ARE causing problems that make no sense. But I'll be damned if I can build a list with any confidence or consistency. I literally do not have time for the investigation this would take. Flutter's overall dependency model and inclusions system is... sloppy, and the community support on libraries is not the speediest. I mean, I get it; many of the libraries out there that don't come from the core group are ones that may solve a certain problem a certain way for a certain developer, but may not necesarily be ready for the Wild West prime time that is the bigger world. I get it. In my one project, I've basically just started stripping out all dependency libraries, writing my own, and not relying on the community. I've pushed this project out ~6 months now, but I'm ending up with 100% in house code. And I STILL have problems with push notifications on Firebase, so maybe it's all a wasted effort. |
The issues here are largely isolated to the firebase libs. They are in progress of being rewritten but it will take time. @chornbe are you by chance using any other firebase services like auth? |
For anyone who disabled swizzling can have a look here. |
In one project, yes (firebase is the entire "back end"). In another, no, just using pushes. |
Thanks, saved for future perusal. Working on something else today, but interested in looking through this. Thanks, man! |
Yeah I had no luck getting swizzling to play nice with Auth and Messaging, but after implementing like I outlined in the link @adar2378 shared, I was able to make everything happy again. To be honest, it's not a huge deal to forego swizzling - you just set it up once and leave it. One less "magic" thing that can break. I've spent a lot of time looking into this. What I found in the end is the sample project included in the messaging app works flawlessly, so there's no problem with it. It breaks when combined with Auth if you have swizzling enabled. But there shouldn't be anything wrong with the messaging lib on its own. I'd double check you've got all of the setup steps correct like the APNS certificate/token uploading to FCM, and make sure the notifications permission is enabled etc. I know you probably read the instructions but it's worth a triple check as there's a lot of steps that can be misconfigured / go wrong. |
A very good news, FCM rework is coming soon https://twitter.com/mikediarmid/status/1319298281290203139?s=20 |
Same to me. Some iOS devices are not receiving notifications. |
I have the same problem as well. |
I have fixed it this problem. Hopefully it's working for all of you. |
Given the major reworks to messaging, I'd kindly request you upgrade to the latest version and follow the reworked docs very closely here for what is/isn't possible on iOS. Will reopen if this is still a problem on the latest version. |
Describe the bug
A couple days ago I notice that my application stopped showing notifications from firebase just on iOS. I send a POST request to https://fcm.googleapis.com/fcm/send containing the payload, when the app is on background nothing happens, when I open the app the method
onMessage
is executed with few fields shown below.The notification was working from about 2 months since first implementation, it was shown when the app was in background, my payload was not changed but it stopped working.
Expected Behaviour
Show notification when app is in background or killed (as before)
My request:

My alternative request with same result:
My code for debug:
The console:
This message is print only when I receive the notification with app open or when I open the app after receive with app closed.
Additional context
I use AdminSDK for PHP for real use and the payload includes android specific data, but I tested on Postman to make sure the problem is not there.
The problem is occurring on production with all users I have checked (TestFlight Beta).
On Android it is working as expected.
If I send just
data
the app continues receiving only when the app is on foreground.Example
The expected behaviour here is to receive the message in background executing immediately
onMessage
when it's not killed, but this happens only when app opens.flutter doctor -v
pubspeck.yml dependencies
The text was updated successfully, but these errors were encountered: