繁体   English   中英

Flutter-Firebase 手机身份验证始终在 iOS 上返回令牌不匹配

[英]Flutter-Firebase phone Auth always returns Token mismatch on iOS

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

其他 Firebase 服务(如 cloud firestore 和电子邮件身份验证)在 iOS 上运行良好。

我确定了以下几点:

- 在 Firebase 中添加了 APN 密钥

-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 中删除任何方法 swizzling 变量,即从 plist 中删除FirebaseAppDelegateProxyEnabled属性

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

    func application(application: 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并且上述设置有效

将 Firebase Auth 版本从 0.14.0 更改为

  firebase_auth:
    git:
      url: https://github.com/collinjackson/plugins.git
      ref: 441417c2fed0ff26bf84a49ab2c5ffd2aa5487de
      path: packages/firebase_auth

修复了我的问题。 有关更多详细信息,请参阅https://github.com/flutter/flutter/issues/35267

暂无
暂无

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

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