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

前端 未结 15 2310
日久生厌
日久生厌 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 03:03

    First of all, you should import all required libs

    import Firebase
    import UserNotifications
    

    later in AppDelegate.swift call next function

    func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
        Messaging.messaging().apnsToken = deviceToken
    
        InstanceID.instanceID().instanceID { (result, error) in
            if let error = error {
                print("Error fetching remote instance ID: \(error)")
            } else if let result = result {
                print("Remote instance ID token: \(result.token)")
            }
        }
    }
    

提交回复
热议问题