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

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

    First register for the firebase token refresh notification:

    NotificationCenter.default.addObserver(self, selector: 
         #selector(tokenRefreshNotification), name:     
         NSNotification.Name.InstanceIDTokenRefresh, object: nil)
    

    Then you can receive the token in the tokenRefreshNotification selector:

    func tokenRefreshNotification(_ notification: Notification) {
        if let refreshedToken = FIRInstanceID.instanceID().token() {
          print("InstanceID token: \(refreshedToken)")
        }
    
        // Connect to FCM since connection may have failed when attempted before having a token.
        connectToFcm()
    }
    

提交回复
热议问题