Firebase SMS Verification on iOS - 'Token Mismatch'
Asked Answered
G

4

13

When attempting to beta test my application with some external users, none of them could properly enter the app using the phone number sms verification. The developers could all use the application when built directly from Xcode, but anyone who installed via a link could not use it.

Each user attempting to sign in / sign up would get an error readout of Token Mismatch - with no other info.

I have a valid production APNS certificate, why is this not working??

Granulite answered 29/9, 2017 at 14:13 Comment(0)
G
37

Steps I took to solve the problem:

  1. Ensure I had both a valid development and production APNS certificate uploaded to the Firebase Dashboard, under 'Project Settings' > 'Cloud Messaging'

dashboardcertificates

  1. 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.

entitlements

  1. 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.

enter image description here

Granulite answered 29/9, 2017 at 14:13 Comment(3)
A well-detailed, well-formatted answer. What a rarity. Keep going!Hesperides
I'm having this issue and none of the following have helped me. Any idea what could still be wrong?Evanesce
Its not working in iOS 16 Simulator but works fine in Real iPhone.Pinson
Q
3

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.

Quartet answered 27/8, 2020 at 22:35 Comment(0)
H
2

In my case I had type:FIRAuthAPNSTokenTypeSandbox in AppDelegate.m

Setting it to type:FIRAuthAPNSTokenTypeProd resolved the issue.

Horrific answered 22/2, 2021 at 7:36 Comment(0)
I
0

in my case change isSandbox:token.type == FIRAuthAPNSTokenTypeSandbox to isSandbox:token.type == FIRAuthAPNSTokenTypeProd in FIRPhoneAuthProvider Pods

Iguana answered 1/4, 2024 at 8:39 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.