I am trying to login account using phone number authentication using firebase.
Initially, i deployed the app with my device and it works fine. But when i tried to deploy app to another device and then it throws me error Token Mismatch
.
I have searched several answers in stackoverflow
and then i found this answer and i followed but it didn't work for me.
I have checked following :
- Ensure I had both a valid development and production APNS certificate uploaded to the Firebase Dashboard, under 'Project Settings' > 'Cloud Messaging'. (My APNS certificate is valid till next year).
- In Xcode, in the .entitlements file, make sure the APS Environment value is set to either 'development' or 'production', depending on your testing situation. (I also checked).
- Finally (this is what I was missing), check inside your AppDelegate.swift and inside the method for
didRegisterForRemoteNotificationsWithDeviceToken
, change the value from .sandbox
to .prod
, or to .unknown
to let the app bundle determine which token type to use, based on your provisioning profile.
This 3rd i also changed
let token = deviceToken.map { String(format: "%02.2hhx", $0) }.joined()
print("==== This is device token ",token)
let data = Data(token.utf8)
Auth.auth().setAPNSToken(data, type: AuthAPNSTokenType.unknown)
But still when i run this app on another device which it always throws me that error.
But when i comment this line of code // Auth.auth().setAPNSToken(data, type: AuthAPNSTokenType.unknown)
and then i run the app after that i uncomment that line of code Auth.auth().setAPNSToken(data, type: AuthAPNSTokenType.unknown)
and then i run the app again and finally it works. But sadly, when i run another iOS device it still gives me error.
I wonder why?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…