Open rednez opened 1 month ago
Hi @rednez , Thanks for submitting this report. I'm able to reproduce this issue.
Reproduced with firebase_messaging
example app
I have the same issue. I can also reproduce it and it impacts our development as we relied on that callback
i'm able to reproduce this issue in iOS 17 and iOS 18. in iOS 15 it works me.
Have you tried downgrading to BoM 2.4.1. I'm not suggesting that's a viable solution, but it seems that BoM 2.5.0 and forward have broken push notifications for some iOS Flutter apps. Could be related to this: https://github.com/firebase/flutterfire/issues/13287
Downgrading to BoM 2.4.1 (firebase_messaging 15.0.4) works for me, any higher version doesn't work.
Have you tried downgrading to BoM 2.4.1. I'm not suggesting that's a viable solution, but it seems that BoM 2.5.0 and forward have broken push notifications for some iOS Flutter apps. Could be related to this: #13287
Downgrading to BoM 2.4.1 (firebase_messaging 15.0.4) works for me, any higher version doesn't work.
I have the same problem. This works in debug for me but not in release.
Have you tried downgrading to BoM 2.4.1. I'm not suggesting that's a viable solution, but it seems that BoM 2.5.0 and forward have broken push notifications for some iOS Flutter apps. Could be related to this: #13287 Downgrading to BoM 2.4.1 (firebase_messaging 15.0.4) works for me, any higher version doesn't work.
I have the same problem. This works in debug for me but not in release.
I hadn't even tried release mode, but now that I do onBackgroundMessage isn't invoked for me either.
In debug, both onBackgroundMessage
and onMessage
are invoked when the app is in background/foreground respectivly. But in release mode, only onMessage
fires in foreground. Background doesn't work.
And in higher versions than BoM 2.4.1, nothing works in debug or release.
EDIT: onBackgroundMessage DOES work on iOS in BoM 2.4.1. However, iOS restricts the number of background push messages/processing an app can do, so it stops working after a while. Then you have to wait a while (no idea how long, I waited two hours) and it will work again. So when developing you may send lots of push messages and get throttled by iOS. I was able to send 8 messages before they stopped coming in.
Edit 2: to be clear, I'm talking about data messages, not notification messages (read firebase messaging docs for more info about the differences)
So I have no issue with BoM 2.4.1 at all!
Any updates on this issue? @SelaseKay
I'm facing this on android and IOS as well. Any update on this?
EDIT: onBackgroundMessage DOES work on iOS in BoM 2.4.1. However, iOS restricts the number of background push messages/processing an app can do, so it stops working after a while. Then you have to wait a while (no idea how long, I waited two hours) and it will work again. So when developing you may send lots of push messages and get throttled by iOS. I was able to send 8 messages before they stopped coming in.
So I have no issue with BoM 2.4.1 at all!
It's not normal behaviour, try to use some chat applications like telegram you get a lot of push without restrictions. That's bug only reproduce on flutter firebase.
EDIT: onBackgroundMessage DOES work on iOS in BoM 2.4.1. However, iOS restricts the number of background push messages/processing an app can do, so it stops working after a while. Then you have to wait a while (no idea how long, I waited two hours) and it will work again. So when developing you may send lots of push messages and get throttled by iOS. I was able to send 8 messages before they stopped coming in. So I have no issue with BoM 2.4.1 at all!
It's not normal behaviour, try to use some chat applications like telegram you get a lot of push without restrictions. That's bug only reproduce on flutter firebase.
No, it's perfectly normal actually. We use data messages (not notification messages) and those are restricted. Read more here: https://firebase.google.com/docs/cloud-messaging/concept-options and https://firebase.google.com/docs/cloud-messaging/flutter/receive
data messages and notification messages are very different and should not be confused. Notification messages never invokes onBackgroundMessage. So chat apps are using notification messages for unlimited push messages like you're talking about.
notification
No, it's perfectly normal actually. We use data messages (not notification messages) and those are restricted. Read more here: https://firebase.google.com/docs/cloud-messaging/concept-options and https://firebase.google.com/docs/cloud-messaging/flutter/receive
data messages and notification messages are very different and should not be confused. Notification messages never invokes onBackgroundMessage. So chat apps are using notification messages for unlimited push messages like you're talking about.
I use notification message, not silent push and get the same behaviour. When message received onBackgroundMessage works (probably 8-10) count after that 'onBackgroundMessage' don't invoked.
I'm facing this on IOS. Any update on this?
Same problem on ios 17,18 please help. Application doesn't work correctly on ios.
Same problem on iOS18, please help.
Same problem on ios 17,18 please help. Application only work on ios 15
Only works on iOS 16 and below. Flutterfire currently only android ? Ios not maintained since 2023 ?
Hey @rednez, I have a fix for background message handling in iOS that should allow you to turn FirebaseAppDelegateProxyEnabled
back to true.
Could you try this branch: https://github.com/firebase/flutterfire/pull/13525, and let me know if it works for you?
Hey @rednez, I have a fix for background message handling in iOS that should allow you to turn
FirebaseAppDelegateProxyEnabled
back to true.Could you try this branch: #13525, and let me know if it works for you?
Hello @russellwheatley.
I installed your 'messaging-13476' branch today. Unfortunately, the onBackgroundMessage
doesn't invokes.
Should I do some additional setup?
In my case I just added this below code
override func application(
_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any],
fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void
) {
super.application(
application, didReceiveRemoteNotification: userInfo, fetchCompletionHandler: completionHandler
)
}
in AppDelegate.swift
file and it started working
Hey @rednez, I have a fix for background message handling in iOS that should allow you to turn
FirebaseAppDelegateProxyEnabled
back to true. Could you try this branch: #13525, and let me know if it works for you?Hello @russellwheatley. I installed your 'messaging-13476' branch today. Unfortunately, the
onBackgroundMessage
doesn't invokes. Should I do some additional setup?
<key>FirebaseAppDelegateProxyEnabled</key>
<true/>
(info.plist file)
cd ios > pod install / pod update
Hey @rednez, I have a fix for background message handling in iOS that should allow you to turn
FirebaseAppDelegateProxyEnabled
back to true. Could you try this branch: #13525, and let me know if it works for you?Hello @russellwheatley. I installed your 'messaging-13476' branch today. Unfortunately, the
onBackgroundMessage
doesn't invokes. Should I do some additional setup?
You must have a different issue as it now works for me and is confirmed by a couple of other users that this fixes background message handling.
In my case I just added this below code
override func application( _ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void ) { super.application( application, didReceiveRemoteNotification: userInfo, fetchCompletionHandler: completionHandler ) }
in
AppDelegate.swift
file and it started working
No need to update your AppDelegate with the fix on the branch I posted.
In my case I just added this below code
override func application( _ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void ) { super.application( application, didReceiveRemoteNotification: userInfo, fetchCompletionHandler: completionHandler ) }
in
AppDelegate.swift
file and it started workingNo need to update your AppDelegate with the fix on the branch I posted.
With the branch It works perfectly :)
@russellwheatley When will the fix be available to pub.dev?? I am using it like this in my pubspec.yaml
firebase_messaging:
git:
url: https://github.com/firebase/flutterfire.git
path: packages/firebase_messaging/firebase_messaging
ref: main
Also added the following to my info.plist
<key>FirebaseAppDelegateProxyEnabled</key>
<true/>
Then cd/ios, pod install and pod update but still no changes
// This callback is still not invoked
@pragma('vm:entry-point')
Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
print("Handling a background message: ${message.messageId}");
}
My console does not print the print statement still. I receive notification if I use the notification parameter when app is minimized but still the callback is never invoked. I send notification the following way:
{
"message":{
"token":"client_token",
"data":{
"hello": "This is a Firebase Cloud Messaging device group message!"
},
// "notification": {
// "title":"Title",
// "body": "body"
// },
"apns": {
"headers": {
"apns-priority": "10"
},
"payload": {
"aps": {
"badge": 1
},
"mutable_content": true,
"content_available" : true
}
}
}
}
Please let me know what I am doing wrong. Stuck here for days."
@niosme Please could you check if the above is ok? As I do not see any changes. Any help is greatly appreciated, Thanks
@russellwheatley When will the fix be available to pub.dev?? I am using it like this in my pubspec.yaml
firebase_messaging: git: url: https://github.com/firebase/flutterfire.git path: packages/firebase_messaging/firebase_messaging ref: main
In the next week they should release the next version as @russellwheatley said :)
Also added the following to my info.plist
<key>FirebaseAppDelegateProxyEnabled</key> <true/>
This inside info.plist is NOT needed. Do a flutter clean flutter pub get
Close and reopen flutter also.
Then cd/ios, pod install and pod update but still no changes
// This callback is still not invoked
@pragma('vm:entry-point') Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async { await Firebase.initializeApp( options: DefaultFirebaseOptions.currentPlatform, ); print("Handling a background message: ${message.messageId}"); }
you should use this also to trigger the function you got inside your initialize function to be fired once.
// Handle background messages
FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
{ "message":{ "token":"client_token", "data":{ "hello": "This is a Firebase Cloud Messaging device group message!" }, // "notification": { // "title":"Title", // "body": "body" // }, "apns": { "headers": { "apns-priority": "10" }, "payload": { "aps": { "badge": 1 }, "mutable_content": true, "content_available" : true } } } }
i use this payload for silent notifications
remove the priority and add those 4 things inside the aps
$apnsConfig = ApnsConfig::fromArray([
'payload' => [
'aps' => [
'mutable-content' => 1,
'content-available' => 1, // Required for silent notifications
'alert' => "", //add this for silent notifications
'sound' => 'default', //add this for silent notifications
],
],
]);
Check this for what ios expects :
https://developer.apple.com/documentation/usernotifications/generating-a-remote-notification
and this for firebase in php:
Hope that helps. Ensure you have used flutter clean and flutter pub get. restart the app or whatever because it maybe cached some things.
I've switched to the latest commit, but onBackgroundMessage only works in debug mode on some devices.
I don't know why. Can somebody help me?
I've switched to the latest commit, but callback for onBackgroundMessage do not invoked.
I've switched to the latest commit, but background notification not working...
iPhone 14 - iOS 18.0.1 – only debug working, release not working
I also tried all above mentioned solution still none of them works for me onBackgroundMessage is not getting invoked tried on Iphone 15 Pro Max - IOS 18.0.1 -- only debug works but release not working
I tried again on last release firebase_messaging 15.1.4
:
data
is sending.notification
(with or without a data
) then it's not working.I tried again on last release
firebase_messaging 15.1.4
:
- Works only in Debug mode and only if
data
is sending.- If send a
notification
(with or without adata
) then it's not working.- iOS 18.1, iPhone 15 Pro.
@kangmyonggyu explained why onBackgroundMessage is not working in release mode. Do you think this explanation is correct?
https://github.com/firebase/flutterfire/issues/13643#issuecomment-2465564267
Is there an existing issue for this?
Are you aware of the differences between iOS and Android background message handling?
Do you have an active Apple Developer account?
Are you using a physical iOS device to test background messages?
Have you enabled "Remote Notifications" & "Background Mode" (Checking options for "Background Processing" & "Remote Notifications") in your app's Xcode project?
Have you created an APNs key in your Apple Developer account & uploaded this APNs key to your Firebase console?
Have you disabled method swizzling for Firebase in your app?
Are you sending messages to your app from the Firebase Admin SDK?
sendToDevice
marked as deprecated, so I don't use it.Have you requested permission from the user to receive notifications?
Have you used the 'Console' application on your macOS device to check if the iOS device's system is throttling your background messages?
There is no any records for
*firebase
filterAdditional context and comments
Run app in Debug
flutter run
mode and in releaseflutter run --release
mode. No matter.main.dart
pubspec.yaml