首页 > 解决方案 > 无法在使用 Flutter 开发的 iOS 应用中使用 Firebase PhoneAuth 成功验证用户身份

问题描述

我正在使用 Firebase PhoneAuth 对用户进行身份验证。我已经按照网络上可靠来源的说明完成了所有集成。

我面临的错误是,我没有在 Firebase Auth 的 verifyPhoneNumber 方法中收到代码发送处理程序的回调。

这是使用的方法,一旦用户输入电话号码,就会调用 signInWithPhone(),然后调用 verifyPhoneNumber()。

Future<AuthUser> signInWithPhone(String phone) async {

 await _firebaseAuth.verifyPhoneNumber(
 phoneNumber: phone,
 timeout: Duration(seconds: 60),
 verificationCompleted: _phoneVerificationCompleted,
 verificationFailed: _phoneVerificationFailed,
 codeSent: _phoneCodeSent,
 codeAutoRetrievalTimeout: _phoneCodeAutoRetrievalTimeout);
 print("Phone Authentication Ended");
 return null;
}

_phoneCodeSent(String verificationId, [int forceResendingToken]) async {
 phoneVerificationId = verificationId;
}

这里应该在发送 otp 时调用 _phoneCodeSent()。在此方法中接收到的 verifyId 是身份验证所必需的。由于没有调用该函数,我没有收到验证 ID,但正在生成 otp。

任何帮助将不胜感激。

标签: iosfirebaseflutterfirebase-authentication

解决方案


请确保您已遵循这些 firebase 与 Flutter 集成的文档,
https:
//firebase.flutter.dev/docs/installation/ios 和 iOS 特定设置,根据此https://firebase.flutter.dev/docs/auth /phone#setup以及 4 个特定的处理程序。


推荐阅读