簡體   English   中英

Firebase電話身份驗證(Flutter)在某些iOS設備中不起作用

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

我已經在使用Firebase電話身份驗證的Flutter應用中實現了電話號碼身份驗證。 在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

嘗試將REVERSE_CLIENT_ID自定義URL方案添加到您的Xcode項目中。

根據firebase文檔:

iOS設置說明:如果您使用的模擬器(無法使用APN的模擬器)或未在您使用的設備上設置APN,則應用驗證可能會使用APN,您必須將URL方案設置為GoogleServices-Info.plist文件中的REVERSE_CLIENT_ID。

如何向您的Xcode項目中添加自定義URL方案:

  1. 打開項目配置:在左樹視圖中雙擊項目名稱。 從“目標”部分中選擇您的應用,然后選擇“信息”選項卡,然后展開“ URL類型”部分。
  2. 單擊+按鈕,然后為您的反向客戶端ID添加URL方案。 要找到此值,請打開Goog​​leService-Info.plist配置文件,然后查找REVERSED_CLIENT_ID密鑰。 復制該鍵的值,然后將其粘貼到配置頁上的“ URL方案”框中。 將其他字段留空。

從這里引用:

https://pub.dev/packages/firebase_auth

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM