I am working on FCM with Flutter. In case of Android it is working fine. But, in case of iOS, it is not working as expected. I am receiving both background and foreground notifications. Foreground notifications are getting handled and working as expected. But, in case of background notifications, I am receiving them, but they are not getting handled. Following is my Flutter code:
class FirebaseNotificationManager {
static Future<void> initFirebaseNotifications() async {
...
...
FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
}
@pragma('vm:entry-point')
static Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
await Firebase.initializeApp();
debugPrint("Handling a background message: ${message.messageId}");
debugPrint('Message data: ${message.data}');
debugPrint('Message notification: ${message.notification?.title}');
debugPrint('Message notification: ${message.notification?.body}');
// Further operations
}
}
I’ve added ‘Push Notification’ and ‘Background Modes’ Capabilities. I’ve also added necessary key in Project Settings in Firebase.
I’ve set FirebaseAppDelegateProxyEnabled: false
in Info.plist.
Sumit Chitnis is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.