mirzemehdi / KMPNotifier

Kotlin Multiplatform Push Notification Library targetting android, iOS, Desktop and Web (JS and Wasm)
http://mirzemehdi.com/KMPNotifier/
Apache License 2.0
340 stars 19 forks source link

No APNS error when requesting token #6

Closed tz2006 closed 7 months ago

tz2006 commented 10 months ago

Hi, every time I try to request the device fcm token I get this error message.

2023-12-30 12:19:55.624090+0200 My firestore[20248:337188] 10.16.0 - [FirebaseMessaging][I-FCM002022] APNS device token not set before retrieving FCM Token for Sender ID '238435558784'.Be sure to re-retrieve the FCM token once the APNS device token is set.
2023-12-30 12:19:55.624209+0200 My firestore[20248:337188] 10.16.0 - [FirebaseMessaging][I-FCM002022] Declining request for FCM Token since no APNS Token specified
FirebasePushNotifier is initialized
Error while getting 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}
TOKEN : null
mirzemehdi commented 10 months ago

@tz2006

1)As shown in ios Setup part did you add this part of code to AppDelegate's didRegisterForRemoteNotificationsWithDeviceToken function?

import SwiftUI
import shared
import FirebaseCore
import FirebaseMessaging

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

      FirebaseApp.configure() //important
      NotifierManager.shared.initialize(configuration: NotificationPlatformConfigurationIos.shared)

    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()
        }
    }
}

2)Can you please log that onNewToken function is called or not?

mirzemehdi commented 7 months ago

Closing this issue due to inactivity. If this is still an issue or need a help, please feel free to reopen the issue and provide additional context or updates. Thank you.

planasmultimedia commented 2 months ago

I'm also getting this error : Error while getting 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}

The local notifications work perfectly. This is my app delegate code :

class AppDelegate: NSObject, UIApplicationDelegate {

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

        //By default showPushNotification value is true.
        //When set showPushNotification to false foreground push  notification will not be shown.
        //You can still get notification content using #onPushNotification listener method.
        NotifierManager.shared.initialize(configuration: NotificationPlatformConfigurationIos(showPushNotification: true, askNotificationPermissionOnStart: false, notificationSoundName: nil))

        return true
    }

    func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
        // Called when a new scene session is being created.
        // Use this method to select a configuration to create the new scene with.
        return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
    }

    func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
          Messaging.messaging().apnsToken = deviceToken
    }
    func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
        // Called when the user discards a scene session.
        // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
        // Use this method to release any resources that were specific to the discarded scenes, as they will not return.
    }
}
mirzemehdi commented 2 months ago

@planasmultimedia maybe you didn't added apn certificate to Firebase? Also Push Notifications capability should be added in ios as well