Ali A. Jalil
Ali A. Jalil

Reputation: 921

iOS: Firebase phone Authenication

I develop an iOS app that use firebase phone authentication, I follow google documentation, but I always have the following error:

If app delegate swizzling is disabled, remote notifications received by UIApplicationDelegate need to be forwarded to FIRAuth's canHandleNotificaton: method.

and My appDelegate:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool
    {

        FirebaseApp.configure()
        return true
    }

    func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
        Auth.auth().setAPNSToken(deviceToken, type: AuthAPNSTokenType.sandbox)
    }


    func application(_ application: UIApplication , didReceiveRemoteNotification notification: [AnyHashable : Any],
                     fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void)
    {
        if Auth.auth().canHandleNotification(notification)
        {
            completionHandler(UIBackgroundFetchResult.noData);
            return
        }
    }

So how can I resolve that?

Upvotes: 1

Views: 4165

Answers (1)

AmmarBaali
AmmarBaali

Reputation: 115

If swizzling is disabled, you need to do two things for phone number auth to work:

Set APNSToken on the FIRAuth instance with your APNs token. This is independent of setting APNs token for FCM (using the FCM client SDK is not required for using phone number auth). Call canHandleNotification on the FIRAuth instance with the remote notification you received from the application:didReceiveRemoteNotification:fetchCompletionHandler: method on your UIApplicationDelegate instance. This is also independent of notifying FCM. It's documented in under section "Receive notifications without swizzling".

Upvotes: 4

Related Questions