Downside Description
I’ve a Flutter app with Firebase Cloud Messaging (FCM) that works completely in Debug mode however fails to show notifications visually in Launch mode on iOS. This is what occurs:
- ✅ Debug mode: Notifications seem appropriately when app is closed/background
- ❌ Launch mode: Notifications are acquired by the app (standing 200) however by no means displayed visually when app is closed/background
- ✅ Firebase Console: Notifications despatched straight from Firebase Console work completely in each modes
- ✅ App foreground: Notifications work in each Debug and Launch when app is open
Present Configuration
iOS AppDelegate.swift
import UIKit
import Flutter
import Firebase
import UserNotifications
import FirebaseMessaging
@principal
@objc class AppDelegate: FlutterAppDelegate {
override func software(
_ software: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
FirebaseApp.configure()
if #out there(iOS 10.0, *) {
UNUserNotificationCenter.present().delegate = self
let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
UNUserNotificationCenter.present().requestAuthorization(
choices: authOptions,
completionHandler: { granted, error in
print("🔔 Notification permission: (granted)")
})
}
software.registerForRemoteNotifications()
GeneratedPluginRegistrant.register(with: self)
return tremendous.software(software, didFinishLaunchingWithOptions: launchOptions)
}
override func software(_ software: UIApplication,
didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Information) {
print("�� APNs machine token: (deviceToken.map { String(format: "%02.2hhx", $0) }.joined())")
Messaging.messaging().apnsToken = deviceToken
}
override func software(
_ software: UIApplication,
didReceiveRemoteNotification userInfo: [AnyHashable: Any],
fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void
) {
print("📱 Notification acquired in background: (userInfo)")
completionHandler(.newData)
}
override func userNotificationCenter(
_ heart: UNUserNotificationCenter,
willPresent notification: UNNotification,
withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void
) {
if #out there(iOS 14.0, *) {
completionHandler([.banner, .sound, .badge])
} else {
completionHandler([.alert, .sound, .badge])
}
}
}
Information.plist
UIBackgroundModes
fetch
remote-notification
FirebaseAppDelegateProxyEnabled
Runner.entitlements
aps-environment
manufacturing
Firebase Perform (Node.js)
const message = {
token: token,
notification: {
title: title,
physique: physique,
},
apns: {
headers: {
"apns-priority": "10",
"apns-push-type": "alert",
},
payload: {
aps: {
alert: {
title: title,
physique: physique,
},
sound: "default",
badge: 1,
},
},
},
};
Flutter Background Handler
@pragma('vm:entry-point')
Future backgroundMessageHandler(RemoteMessage remoteMessage) async {
await Firebase.initializeApp();
debugPrint('�� Background message acquired: ${remoteMessage.notification?.title}');
return Future.worth(true);
}
Key Observations
- FCM tokens are legitimate (standing 200 from Firebase Perform)
- APNs configuration works (Firebase Console notifications work)
- Permissions are granted (notifications work when app is foreground)
- Background modes are enabled in Information.plist
- AppDelegate strategies are known as (logs present notifications are acquired)
Query
What could possibly be inflicting iOS to obtain FCM notifications in Launch mode however not show them visually when the app is closed or in background? The truth that Firebase Console notifications work suggests the APNs configuration is right, however there’s one thing particular about my customized Firebase Perform payload or iOS configuration that is stopping visible show in Launch mode.
- ✅ Verified APNs setting is about to “manufacturing” in entitlements
- ✅ Confirmed
software.registerForRemoteNotifications()
is known as - ✅ Added
@pragma('vm:entry-point')
to forestall tree shaking - ✅ Set
FirebaseAppDelegateProxyEnabled
to false - ✅ Simplified APNs payload (eliminated
content-available: 1
) - ✅ Verified Xcode Signing & Capabilities has Push Notifications enabled
- ✅ Examined with recent FCM tokens as a substitute of saved ones