Change/update Firebase notification token or instance id forcefully via code?

前端 未结 4 951
轻奢々
轻奢々 2020-12-24 08:33

What should I do that for changing or requesting the token in firebase? the unique token generated by firebase on the basis of device information.

4条回答
  •  佛祖请我去吃肉
    2020-12-24 09:18

    for now InstanceID.instanceID().token() is deprecated.

    You should use this:

    let instance = InstanceID.instanceID()
    instance.deleteID { (error) in
      print(error.debugDescription)
    }
    
    instance.instanceID { (result, error) in
      if let error = error {
        print("Error fetching remote instange ID: \(error)")
      } else {
        print("Remote instance ID token: \(String(describing: result?.token))")
      }
    }
    Messaging.messaging().shouldEstablishDirectChannel = true
    

    Then in AppDelegate:

    extension AppDelegate: MessagingDelegate {
    
    func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String) {
        //Here is your new FCM token
        print("Registered with FCM with token:", fcmToken)
    }
    

提交回复
热议问题