Skip to content

iOS: NotifierManager.getPushNotifier().getToken() returns null, no push notifications received #151

@michredk

Description

@michredk

KMPNotifier and Kotlin version:
kmpnotifier version: v1.6.0
kotlin version: 2.2.0

Describe the bug
Push notifications work correctly on Android, but fail on iOS.
On iOS, NotifierManager.getPushNotifier().getToken() always returns null, and the app cannot receive push notifications.

Steps taken:

  • Added Background Modes (Remote notifications) and Push Notifications capabilities.
  • Configured Firebase with an APNs Authentication Key.
  • Implemented didRegisterForRemoteNotificationsWithDeviceToken to set Messaging.messaging().apnsToken.
  • I tried setting FirebaseAppDelegateProxyEnabled to NO, as suggested elsewhere.

Logs and code:

12.1.0 - [FirebaseMessaging][I-FCM002022] APNS device token not set before retrieving FCM Token for Sender ID '686271794836'.Be sure to re-retrieve the FCM token once the APNS device token is set.

12.1.0 - [FirebaseMessaging][I-FCM002022] Declining request for FCM Token since no APNS Token specified

12.1.0 - [FirebaseMessaging][I-FCM002010] The subscription operation failed due to an error getting the FCM token: Error Domain=com.google.fcm Code=505 "No APNS token specified before fetching FCM Token" UserInfo={NSLocalizedFailureReason=No APNS token specified before fetching FCM Token}.

09-22 22:03:02.060 ❤️ ERROR Napier - firebasePushToken : null

iOSApp.swift:

import SwiftUI
import FirebaseCore
import ComposeApp
import FirebaseMessaging

class AppDelegate: NSObject, UIApplicationDelegate {

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {

        MainViewControllerKt.debugBuild()
        FirebaseApp.configure()

        startKoin()

        NotifierManager.shared.initialize(configuration: NotificationPlatformConfigurationIos(
            showPushNotification: true,
            askNotificationPermissionOnStart: true,
            notificationSoundName: nil
            )
        )

        return true
    }

    func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
        Messaging.messaging().apnsToken = deviceToken
    }

}

@main
struct iOSApp: App {

    @UIApplicationDelegateAdaptor(AppDelegate.self) var delegate

    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions