Sotiris Kaniras
Sotiris Kaniras

Reputation: 680

PhoneAuthProvider just started throwing error (possibly on simulator only)

Out of nowhere, the PhoneAuthProvider.provider().verifyPhoneNumber(phoneNumber, uiDelegate: nil) started failing on my simulator, but still works on my device (same build obviously). I've tried both real phone numbers and testing phone numbers.

I'm on SDK version 9.6.0 and run it on an iOS 16.1 simulator.

Here's the error I'm getting: Error Domain=FIRAuthErrorDomain Code=17048 "Token mismatch" UserInfo={NSLocalizedDescription=Token mismatch, FIRAuthErrorUserInfoNameKey=INVALID_APP_CREDENTIAL}

Here's my AppDelegate:

extension AppDelegate: UNUserNotificationCenterDelegate {
    func userNotificationCenter(
        _ center: UNUserNotificationCenter,
        didReceive response: UNNotificationResponse,
        withCompletionHandler completionHandler: @escaping () -> Void
    ) {
        let userInfo = response.notification.request.content.userInfo
        
        completionHandler()
    }
    
    func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
        Auth.auth().setAPNSToken(deviceToken, type: .unknown)
        Messaging.messaging().apnsToken = deviceToken
    }
    
    func application(_ application: UIApplication, didReceiveRemoteNotification notification: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
        Messaging.messaging().appDidReceiveMessage(notification)
        
        if (Auth.auth().canHandleNotification(notification)) {
            completionHandler(.noData)
            return
        }
    }
}

extension AppDelegate: MessagingDelegate {
    func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String?) {
        let tokenDict = ["token": fcmToken ?? ""]
        
        NotificationCenter.default.post(
            name: Notification.Name("FCMToken"),
            object: nil,
            userInfo: tokenDict)
    }
}

Also here’s my Firebase certificates setup: enter image description here

Any ideas?

EDIT: Now that I think about it, yesterday I updated my macOS to 13.0.1. Could it have anything to do with it?

EDIT 2: It seems that it still works on an iOS 15 simulator

Upvotes: 0

Views: 437

Answers (1)

Khal
Khal

Reputation: 820

I had the same issue, I finally nailed it : I updated Firebase to the latest version (10.2) and now it works on iOS 16 too :-)

Upvotes: 1

Related Questions