集成适用于iOS的Flutter Firebase电话身份验证的问题

时间:2019-06-16 19:30:06

标签: ios firebase flutter dart firebase-authentication

我知道这个问题已经问过几次了,但是没有一个问题能帮助我解决问题。我遵循了文档中提到的所有内容,将Firebase Auth配置为iOS。另外,我正在使用Flutter进行应用程序开发。

这是用于验证电话号码的飞镖代码:

await _auth.verifyPhoneNumber(
        phoneNumber: _phoneNumberController.text,
        timeout: const Duration(minutes: 2),
        verificationCompleted: (user) {
          print('verification completed');
        },
        verificationFailed: (AuthException authException) {
          _scaffoldKey.currentState.showSnackBar(SnackBar(
            content: Text(
                'Phone number verification failed. Code: ${authException.code}. Message: ${authException.message}'),
          ));
        },
        codeSent: (String verificationId, [int forceResendingToken]) {
          _verificationId = verificationId;
          _scaffoldKey.currentState.showSnackBar(SnackBar(
            content: const Text(
                'Please check your phone for the verification code.'),
          ));
        },
        codeAutoRetrievalTimeout: (String verificationId) {
          _verificationId = verificationId;
        });

当我提供电话号码并进行验证时,它会显示一条错误消息:

  

如果禁用了应用程序委托模糊处理,则需要将UIApplicationDelegate收到的远程通知转发到FIRAuth的canHandleNotification:方法。

因为我使用的是Flutter,所以我只是将以下代码粘贴到AppDelegate.swift中,我不确定它是否正确。我将在下面粘贴整个课程:

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
  override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?
  ) -> Bool {
    FirebaseApp.configure()
    GeneratedPluginRegistrant.register(with: self)

    //return super.application(application, didFinishLaunchingWithOptions: launchOptions)
    return true
  }

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

        // Further handling of the device token if needed by the app
        // ...
    }

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

    // For iOS 9+
    override func application(_ application: UIApplication, open url: URL,
                              options: [UIApplicationOpenURLOptionsKey : Any]) -> Bool {
        if Auth.auth().canHandle(url) {
            return true
        }
        // URL not auth related, developer should handle it.
        return true;
    }
}

到目前为止,我已经尝试过:

  1. 创建启用了推送通知的应用程序ID,并在Apple Developer帐户中生成密钥和配置文件
  2. 将密钥上传到iOS应用下的Firebase控制台
  3. 在Xcode中为reCaptcha配置了自定义URL方案,在Xcode功能下启用了推送通知和后台远程通知
  4. 将以上指定的代码添加到AppDelegate.swift
  5. 清理并运行了项目

版本信息:

  • firebase-core:0.3.0 ^ 2
  • firebase-auth:0.8.1 + 4

我可能会错过一些信息,但我会尽力包括所有必要的内容。

任何解决此问题的方法/想法都将不胜感激。

谢谢。

0 个答案:

没有答案