-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Description
[REQUIRED] Step 2: Describe your environment
- Xcode version: 10.1
- Firebase SDK version: 5.13.0
- Firebase Component: Auth, Core, Database, Messaging, Storage
- Swift Version: 4.2
[REQUIRED] Step 3: Describe the problem
Recently transferred my app to a new Apple ID. I created/upload all of the new certificates for push notifications to firebase console (APN Auth Key). Also, set up other IOS certificates ("IOS distribution", "Apple Push Services") and made sure appID was added with push notifications enabled. My problem is the old firebase register tokens already stored in my database don't seem to work anymore. Once I reinstall the app or get the token to refresh the push notifications work. But again if I were to use the old tokens that were created before the app transfer the push notification fails to send.
What would be the best way to create new push notification tokens for users that have the old token? After reading the firebase docs the only way to create a new token would be if the user does one of the three things below.
- The app is restored on a new device
- The user uninstalls/reinstall
- The user clears app data.
Yet all of those things seem like something the user would have to do themselves.
After doing a bit more research I found this similar issue Change/update Firebase notification token or instance id forcefully via code?. There suggestion was to
1) Delete old Token
let instance = InstanceID.instanceID()
instance.deleteID { (error) in
print(error.debugDescription)
}
2) Request for new token
if let token = InstanceID.instanceID().token() {
print("Token : \(token)");
} else {
print(“Error: unable to fetch token");
}
Messaging.messaging().shouldEstablishDirectChannel = true
Which worked, when I call deleteID on the instanceID the MessagingDelegate's "didReceiveRegistrationToken" is called with the new fcmToken. I then update Database with new token. But this new fcmToken does not work, when I try to send a push notification through the firebase cloud messaging console nothing is received on the phones end. Yet if I were to delete the app and reinstall it, the first fcmToken works. The App receives all push notifications until I try to force update the FCMToken.
Again my goal is to update users with old FCMTokens to new ones so they can receive push notifications without having to reinstall the app or get the old FCM token to work.