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

前端 未结 4 946
轻奢々
轻奢々 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

    Now i got my answer after facing many troubles for generating new or change token of firebase for push notification.

    1) Delete old Firebase token

    let instance = FIRInstanceID.instanceID()
    _ = FIRInstanceID.delete(instance)
    FIRInstanceID.instanceID().delete { (err:Error?) in
        if err != nil{
            print(err.debugDescription);
        } else {
            print("Token Deleted");
        }
    }
    

    2) Request new Firebase token

    if let token = FIRInstanceID.instanceID().token() {
        print("Token \(token) fetched");
    } else {
        print("Unable to fetch token");
    }
    
    FIRMessaging.messaging().connect { (error) in
        if (error != nil) {
            print("Error connecting to FCM. \(error.debugDescription)")
        } else {
            print("Connected to FCM.")
        }
    }
    

    UPDATE FOR SWIFT 4 & Firebase 4.8.2 (Follow simple two steps)

提交回复
热议问题