I’m having an issue with Firebase Cloud Messaging (FCM) where direct messages sent via the FCM token work perfectly, but notifications from Firebase Messaging Campaigns don’t reach my iOS app. Here’s what I’ve tried and confirmed so far:
Setup & What’s Working:
- Direct Messages via FCM Token: These are received by the app without any issues.
- Notification Permissions: All necessary permissions are granted on the device.
- APNs Authentication Key: This is configured in Firebase, and the Firebase Console shows the campaign status as “Completed,” but messages don’t appear on the target device.
My Steps:
- Uploaded the APNs Authentication Key in Firebase:
- Opened Apple Developer Console > Certificates, Identifiers & Profiles > Keys > Registered a New Key > Checked APNs service.
- Downloaded the APNs Key and uploaded it to Firebase under Project Settings > Cloud Messaging.
- Firebase Console Campaign Setup:
- Notification title and body are configured.
- Target set to “All Users” (for testing purposes).
- Message settings: sound enabled, Apple badge enabled, badge count set to 1, expiration set to 4 weeks.
- Code Setup (relevant parts):
- Using Firebase for authentication and data storage with Firestore.
- Configured AppDelegate for Firebase, FCM, and APNs token registration.
- Implemented
UNUserNotificationCenterDelegate
methods to show notifications when the app is in the foreground.
Observed Behavior:
- The Firebase Console indicates the campaign is “Completed,” but the messages are not received on the device.
- There are no errors in the Firebase Console or my Xcode logs when sending the campaign.
- My AppDelegate is correctly handling the APNs token and FCM token registration.
Here’s My Code Setup in AppDelegate:
class AppDelegate: NSObject, UIApplicationDelegate, MessagingDelegate, UNUserNotificationCenterDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
FirebaseApp.configure()
Messaging.messaging().delegate = self
UNUserNotificationCenter.current().delegate = self
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) { granted, error in
if granted { print("Notification permission granted") }
}
application.registerForRemoteNotifications()
return true
}
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
Messaging.messaging().apnsToken = deviceToken
}
func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String?) {
print("FCM Token received: \\(String(describing: fcmToken))")
}
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
completionHandler([.alert, .badge, .sound])
}
}