iOS:Firebase电话认证

时间:2018-09-10 16:54:03

标签: swift firebase firebase-authentication

我开发了一个使用Firebase电话身份验证的iOS应用,我遵循google文档,但始终出现以下错误:

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

和我的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
        }
    }

那我该如何解决呢?

1 个答案:

答案 0 :(得分:1)

如果禁用了打扰功能,则需要执行两项操作才能使电话号码验证生效:

使用您的APNs令牌在FIRAuth实例上设置APNSToken。这与为FCM设置APNs令牌无关(使用FCM客户端SDK不需要使用电话号码身份验证)。 使用从UIApplicationDelegate实例上的 application:didReceiveRemoteNotification:fetchCompletionHandler :方法收到的远程通知,在FIRAuth实例上调用 canHandleNotification 。这也独立于通知FCM。

它记录在https://firebase.google.com/docs/auth/ios/phone-auth下“接收通知而不会产生混乱”部分。