Firebase SMS Verification on iOS - 'Token Mismatch'
Steps I took to solve the problem:
- Ensure I had both a valid
development
andproduction
APNS certificate uploaded to the Firebase Dashboard, under 'Project Settings' > 'Cloud Messaging'
- In Xcode, in the
<my app>
.entitlements file, make sure the APS Environment value is set to either 'development' or 'production', depending on your testing situation.
- Finally (this is what I was missing), check inside your
AppDelegate.swift
and inside the method fordidRegisterForRemoteNotificationsWithDeviceToken
, 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.
Step 1: import Firebase
2. Add the following to your AppDelegate:-
override func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
let firebaseAuth = Auth.auth()
firebaseAuth.setAPNSToken(deviceToken, type: AuthAPNSTokenType.unknown)
}
override func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
let firebaseAuth = Auth.auth()
if (firebaseAuth.canHandleNotification(userInfo)){
print(userInfo)
return
}
}
At least this worked for me.