【问题标题】:Firebase Phone Auth (Flutter) is not working in some iOS devicesFirebase 电话身份验证 (Flutter) 在某些 iOS 设备中不起作用
【发布时间】:2019-10-05 20:49:42
【问题描述】:

我已经使用 firebase 电话身份验证在颤振应用中实现了电话号码身份验证。它在 Android 中运行良好。但它在 iOS 中无法正常工作,因为许多用户在提交短信验证码后都面临错误,尽管很多其他人都可以正常使用该应用程序。这种情况的可能原因是什么?我已经在下面提交了我的代码。

号码提交

void _verifyPhoneNumber() async {

final PhoneVerificationCompleted verificationCompleted =
    (AuthCredential phoneAuthCredential) async {

  final FirebaseUser user =
      await _auth.signInWithCredential(phoneAuthCredential);

  if (user != null) {
    phone = user.phoneNumber;
    fid = user.uid;
    saveLogin(context);
  } else {
    _showErrorDialog("User Verification Error!");
  }
};

final PhoneVerificationFailed verificationFailed =
    (AuthException authException) {
  _showErrorDialog("Phone Verification Failed");
};

final PhoneCodeSent codeSent =
    (String verificationId, [int forceResendingToken]) async {
  _verificationId = verificationId;
  setState(() {
    _title = "Verify SMS Code";
    phoneInput = false;
    phoneSubmit = false;
    codeInput = true;
    codeSubmit = true;
  });
};

final PhoneCodeAutoRetrievalTimeout codeAutoRetrievalTimeout =
    (String verificationId) async {
  _verificationId = verificationId;
  setState(() {
    _title = "Verify SMS Code";
    phoneInput = false;
    phoneSubmit = false;
    codeInput = true;
    codeSubmit = true;
  });
};

await _auth.verifyPhoneNumber(
    phoneNumber: "+880" + _mobileNumber,
    timeout: const Duration(seconds: 5),
    verificationCompleted: verificationCompleted,
    verificationFailed: verificationFailed,
    codeSent: codeSent,
    codeAutoRetrievalTimeout: codeAutoRetrievalTimeout);
  }

代码提交

void _signInWithPhoneNumber(String _code) async {

final AuthCredential credential = PhoneAuthProvider.getCredential(
  verificationId: _verificationId,
  smsCode: _code,
);
final FirebaseUser user = await _auth.signInWithCredential(credential);
if (user != null) {
  phone = user.phoneNumber;
  fid = user.uid;
  saveLogin(context);
} else {
  _showErrorDialog("User Verification Error!");
}
  }

使用的插件

google_sign_in:^4.0.1+3

firebase_auth:^0.11.0

【问题讨论】:

  • 我面临着类似的问题。您的应用程序是否在每次重新启动应用程序时都要求 OTP?如果是这样,那么我想我可以告诉你问题
  • @AmitKabra 用户注销或重新安装应用后。
  • 每次在 IOS 上重新启动应用程序时,我的应用程序都会要求 OTP。关闭应用程序后,它不会在 Android 上注销。你在IOS上遇到过类似的问题吗?
  • 没有。我没有面对。
  • 您是否介意分享您的电话登录代码以及重新启动应用时会触发什么?

标签: android ios dart flutter


【解决方案1】:

尝试将 REVERSE_CLIENT_ID 自定义 URL 方案添加到您的 Xcode 项目。

根据火力基地文档:

iOS 设置注意事项:应用验证可能会使用 APN,如果使用模拟器(其中 APN 不起作用)或未在您使用的设备上设置 APN,则必须将 URL 方案设置为来自 GoogleServices-Info 的 REVERSE_CLIENT_ID。 plist 文件。

如何将自定义 URL 方案添加到您的 Xcode 项目:

  1. 打开您的项目配置:双击左侧树视图中的项目名称。从 TARGETS 部分选择您的应用,然后选择 Info 选项卡,然后展开 URL Types 部分。
  2. 单击 + 按钮,并为您的反向客户端 ID 添加 URL 方案。要查找此值,请打开 GoogleService-Info.plist 配置文件,然后查找 REVERSED_CLIENT_ID 键。复制该键的值,并将其粘贴到配置页面上的 URL 方案框中。将其他字段留空。

来自这里的参考:

https://pub.dev/packages/firebase_auth

https://firebase.google.com/docs/auth/ios/phone-auth

【讨论】:

    猜你喜欢
    • 2020-03-26
    • 2019-09-18
    • 1970-01-01
    • 1970-01-01
    • 2021-06-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多