ios - Flutter-Firebase phone Auth 总是在 iOS 上返回 token 不匹配

标签 ios flutter firebase-authentication

我正在尝试使用电话身份验证,它在 Android 上按预期工作,但在 iOS 上我总是遇到 token 不匹配并且收不到代码。

其他 Firebase 服务,例如 cloud firestore 和 email Auth,在 iOS 上运行良好。

我确定了以下内容:

-在 Firebase 中添加 APN key

-Google 服务文件已更新

-后台模式和推送通知功能开启

错误消息来自 PhoneVerificationFailed

Future<void> _verifyPhoneNumber() async {

    setState(() {
      _message = '';
    });

    final PhoneVerificationCompleted verificationCompleted =
        (AuthCredential phoneAuthCredential) async {

      await _auth.signInWithCredential(phoneAuthCredential);

      setState(() {
        _message = 'Received phone auth credential: $phoneAuthCredential';

      });

    };

    final PhoneVerificationFailed verificationFailed =
        (AuthException authException) {
      setState(() {
        _message = '********************\n\n'
            'Phone number verification failed. Code: ${authException.code}.'
            '\n Message: ${authException.message}'
            '\n\n********************';
      });
    };

    final PhoneCodeSent codeSent =
        (String verificationId, [int forceResendingToken]) async {
      _verificationId = verificationId;

      setState(() {
        _message = 'waiting for code';
        //waitingCode = true;
      });
    };

    final PhoneCodeAutoRetrievalTimeout codeAutoRetrievalTimeout =
        (String verificationId) {
      _verificationId = verificationId;
    };

    try {
      await _auth.verifyPhoneNumber(
          phoneNumber: number,
          timeout: const Duration(seconds: 30),
          verificationCompleted: verificationCompleted,
          verificationFailed: verificationFailed,
          codeSent: codeSent,
          codeAutoRetrievalTimeout: codeAutoRetrievalTimeout);
    } catch (e) {
      print('Error is $e');
    }
  }

我从日志中获取这些消息

Userinfo {
    "com.google.firebase.auth" =     {
        warning = "This fake notification should be forwarded to Firebase Auth.";
    };
}
UserDate : {
    "com.google.firebase.auth" =     {
        warning = "This fake notification should be forwarded to Firebase Auth.";
    };
}
UserDate Json : {
  "com.google.firebase.auth" : {
    "warning" : "This fake notification should be forwarded to Firebase Auth."
  }
}
flutter: 


TRUE
flutter: Call Back {
  "com.google.firebase.auth" : {
    "warning" : "This fake notification should be forwarded to Firebase Auth."
  }
}

最佳答案

我知道现在回答这个问题为时已晚。但我最近也遇到了同样的错误。我在 iOS 上解决了这个问题。您的整个配置必须有效。您需要进行两项设置。

  • 从 GoogleService-info.plist 中删除任何方法调配变量 即从 plist 中删除 FirebaseAppDelegateProxyEnabled 属性

  • 在 AppDelegate.swift 中,覆盖此方法并设置以下内容

    函数应用程序(应用程序:UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) { Messaging.messaging().apnsToken = deviceToken

它在 https://firebase.google.com/docs/cloud-messaging/ios/client#token-swizzle-disabled 中提到

我正在使用 firebase_messaging: ^6.0.16 并且上述设置有效

关于ios - Flutter-Firebase phone Auth 总是在 iOS 上返回 token 不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57395948/

相关文章:

iOS 以编程方式执行 Segue 时查看 Controller 生命周期

flutter - 从轮播 slider 获取索引-Flutter

curl - 在Flutter中使用Dio进行POST时遇到问题

flutter - 如何根据在 flutter 中单击哪个导航栏按钮来更改脚手架主体?

typescript - 带有 typescript 的 Firebase 3.0

android - Firebase OTP 在调试 apk 上工作正常,但不能发布 apk

java - Firebase 纯 Java 客户端

objective-c - 我可以有一个不是模态呈现的相机吗?如何?

ios - UIBarButtonItem 超出屏幕

ios - 为 swift 2 中的按钮创建可缩放的三行菜单导航图标