Correct way to retrieve token for FCM - iOS 10 Swift 3

前端 未结 15 2048
日久生厌
日久生厌 2021-01-31 02:42

i had implement Firebase with FirebaseAuth/FCM etc and did sent notification successfully through Firebase Console.

However i would need to push the notification from m

15条回答
  •  遇见更好的自我
    2021-01-31 02:55

    The tokenRefreshNotification function doesn't always get called when launching the app.

    However, when placing the code inside the regular didRegisterForRemoteNotificationsWithDeviceToken delegate function, I can get the token every time:

    func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
        if let refreshedToken = InstanceID.instanceID().token() {
            print("InstanceID token: \(refreshedToken)")
        }
    }
    

    (Swift 3 + Firebase 4.0.4)

提交回复
热议问题