繁体   English   中英

Firebase 迁移 iOS 电话号码输入的数字

[英]Digits to firebase migration iOS Phone number input

我一直在使用数字通过电话号码登录。 我必须迁移到 Firebase,但有几件事我很困惑:

我的流程是:1)用户通过电话号码点击了自定义按钮登录,该按钮有操作

@IBAction func loginViaDigits(_ sender: AnyObject) {
    let digits = Digits.sharedInstance()
    let configuration = DGTAuthenticationConfiguration(accountFields: .defaultOptionMask)
    configuration?.phoneNumber = "+44"
    digits.authenticate(with: self.navigationController, configuration: configuration!) { session, error in
        if error == nil {
            let digits = Digits.sharedInstance()
            let oauthSigning = DGTOAuthSigning(authConfig:digits.authConfig, authSession:digits.session())
            let authHeaders = oauthSigning?.oAuthEchoHeadersToVerifyCredentials()
            self.startActivityIndicator()
            NetworkApiCall(apiRequest: SignInApiRequest(digits_auth: authHeaders as! [NSObject : AnyObject])).run() { (result: SignInApiResponse?, error: NSError?) in
                if error != nil {
                    self.stopActivityIndicator()
                    UIUtils.showInfoAlert("Some error occurred!", controller: self)
                    return;
                }

                guard let response = result else {
                    self.stopActivityIndicator()
                    UIUtils.showInfoAlert("Some error occurred!", controller: self)
                    return;
                }

                ...
        }
    }
}

2)基本上,用户通过电话号码按钮点击登录,数字显示他们获取电话号码的弹出窗口,然后他们要求输入验证码,当他们完成后,我会在我的回调方法中获得 oauth 参数并将它们传递给我的服务器。

我的问题是:1)我是否需要自己构建电话号码输入和验证码输入屏幕,或者firebase像数字一样提供它们?

2)如果有人实际上已经迁移了这种流,一些指针会非常有帮助。

正如 Lazy King 所建议的,我正在尝试使用 FirebaseAuthUI,但我的 AppDelegate 似乎缺少一些功能:

Firebase 的 AppDelegate 更改:

func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
    // Pass device token to auth
    Auth.auth().setAPNSToken(deviceToken, type: AuthAPNSTokenType.prod)
}

func application(_ application: UIApplication,
                 didReceiveRemoteNotification notification: [AnyHashable : Any],
                 fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
    if Auth.auth().canHandleNotification(notification) {
        completionHandler(.noData)
        return
    }
    // This notification is not auth related, developer should handle it.
}

但我仍然不断收到此错误:Error Domain=FIRAuthErrorDomain Code=17054“如果禁用了应用程序委托调动,则 UIApplicationDelegate 收到的远程通知需要转发到 FIRAuth 的 canHandleNotificaton: 方法。”

您可以使用 FirebaseAuth UI 或为您自己设计一个 UI。 对于我的一个项目,我使用了 FirebaseAuth UI。 这是一步一步的:

  1. 添加 FireBase Auth 和 Auth UI pod 'Firebase/Auth', '~> 4.0.0' 和 pod 'FirebaseUI/Phone', '~> 4.0'

  2. 在 Appdelegate 文件注册推送通知中,这是强制性的。 谷歌用户推送通知进行首次验证。 didRegisterForRemoteNotificationsWithDeviceToken添加这一行:

     Auth.auth().setAPNSToken(deviceToken, type:AuthAPNSTokenType.prod)//.sandbox for development
  3. 您还需要在 Firebase 控制台上设置 Google 通知

  4. 关于电话登录按钮功能

    var uiAuth = FUIAuth.defaultAuthUI() ; uiAuth?.delegate = self; var phoneVC = FUIPhoneAuth(authUI: uiAuth!) uiAuth.providers = [phoneVC]; phoneVC.signIn(withPresenting: self)
  5. 实现委托功能

  6. 在 Appdelegate 接收通知功能中添加代码

     if Auth.auth().canHandleNotification(userInfo) { completionHandler(UIBackgroundFetchResult.noData) return }

如果您使用 iOS 10 或更高版本,则

@available(iOS 10.0, *)
internal func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {

    let userInfo = response.notification.request.content.userInfo
    if Auth.auth().canHandleNotification(userInfo) {
        completionHandler()
        return
    }

    completionHandler()
}

希望它会奏效。

请在 Firebase.configure() 之前注册通知。 有用

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM