简体   繁体   English

Firebase电话身份验证(Flutter)在某些iOS设备中不起作用

[英]Firebase Phone Auth (Flutter) is not working in some iOS devices

I have implemented phone number authentication in a flutter app using firebase phone auth. 我已经在使用Firebase电话身份验证的Flutter应用中实现了电话号码身份验证。 It is working fine in Android. 在Android中运行正常。 But it is not working properly in iOS as many users are facing error after they submit sms verification code, though a lot others are using the app just fine. 但这在iOS中无法正常运行,因为许多用户在提交短信验证码后都遇到了错误,尽管很多其他人都在使用该应用。 What can be the possible reasons for this scenario? 这种情况可能是什么原因? I have submitted my code below. 我已经在下面提交了我的代码。

Number Submission 号码提交

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);
  }

Code Submission 代码提交

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!");
}
  }

Plugins Used 使用的插件

google_sign_in: ^4.0.1+3 google_sign_in:^ 4.0.1 + 3

firebase_auth: ^0.11.0 firebase_auth:^ 0.11.0

Try adding the REVERSE_CLIENT_ID custom URL schemes to your Xcode project. 尝试将REVERSE_CLIENT_ID自定义URL方案添加到您的Xcode项目中。

According to the firebase documentation: 根据firebase文档:

iOS setup note: App verification may use APNs, if using a simulator (where APNs does not work) or APNs is not setup on the device you are using you must set the URL Schemes to the REVERSE_CLIENT_ID from the GoogleServices-Info.plist file. iOS设置说明:如果您使用的模拟器(无法使用APN的模拟器)或未在您使用的设备上设置APN,则应用验证可能会使用APN,您必须将URL方案设置为GoogleServices-Info.plist文件中的REVERSE_CLIENT_ID。

How to add custom URL schemes to your Xcode project: 如何向您的Xcode项目中添加自定义URL方案:

  1. Open your project configuration: double-click the project name in the left tree view. 打开项目配置:在左树视图中双击项目名称。 Select your app from the TARGETS section, then select the Info tab, and expand the URL Types section. 从“目标”部分中选择您的应用,然后选择“信息”选项卡,然后展开“ URL类型”部分。
  2. Click the + button, and add a URL scheme for your reversed client ID. 单击+按钮,然后为您的反向客户端ID添加URL方案。 To find this value, open the GoogleService-Info.plist configuration file, and look for the REVERSED_CLIENT_ID key. 要找到此值,请打开Goog​​leService-Info.plist配置文件,然后查找REVERSED_CLIENT_ID密钥。 Copy the value of that key, and paste it into the URL Schemes box on the configuration page. 复制该键的值,然后将其粘贴到配置页上的“ URL方案”框中。 Leave the other fields blank. 将其他字段留空。

References from here: 从这里引用:

https://pub.dev/packages/firebase_auth https://pub.dev/packages/firebase_auth

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

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

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