Replies: 3 comments 2 replies
|
The intended Dart entry point is still @pragma('vm:entry-point')
Future<void> firebaseMessagingBackgroundHandler(RemoteMessage message) async {
await Firebase.initializeApp(); // pass options if your setup requires them
await persistPayload(message.data);
}
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
FirebaseMessaging.onBackgroundMessage(firebaseMessagingBackgroundHandler);
runApp(const App());
}The native callback arriving before your Dart Also verify the delivery prerequisites:
"apns": {
"headers": {
"apns-push-type": "background",
"apns-priority": "5"
},
"payload": { "aps": { "content-available": 1 } }
}
These lifecycle constraints and handler requirements are documented in Firebase's Flutter receive guide. If the Objective-C delegate consistently fires but the Dart handler does not with the minimal registration above on the latest |
|
Thank you very much for the detailed response. What I don't understand is the following paragraph:
How can the plugin routine call Another point I don't understand is this sentence in the prerequisites:
Does that basically mean that background messages can't be delivered at all on iOS if the app isn't running in the background? As a user, I wouldn't even notice if iOS killed the app when it's not in the foreground. |
|
It's an iOS limitation, not FlutterFire. To clarify: the push notification itself (the banner, sound, badge) is always delivered and shown to the user, even after force-quit. iOS handles that at the system level. The user sees it, taps it, and the app opens. What doesn't work after force-quit is silent background processing. When you send a push with only Apple documents this in:
There's one exception: if iOS kills the app due to low memory (the user didn't swipe it away), silent pushes still work. iOS treats that as a suspend, not a termination, and will relaunch the app in the background to process the message. The user never notices this happened. |
Uh oh!
There was an error while loading. Please reload this page.
I send silent notifications to a Flutter app.
If the app is running in the background, the
onBackgroundMessagehandler is called.However, if the app is terminated it is launched, but neither is
onBackgroundMessagecalled, nor doesFirebaseMessaging.instance.getInitialMessage()return anything (returns null).What is the intended method for accessing the payload of the message that triggered the app to launch?
I did some debugging and see
being called, which calls
[_channel invokeMethod:@"Messaging#onBackgroundMessage"..., but this is even beforemain()of my flutter code is being called.All reactions