【问题标题】:Not able to successfully authenticate user using Firebase PhoneAuth in iOS App developed using Flutter无法在使用 Flutter 开发的 iOS 应用中使用 Firebase PhoneAuth 成功验证用户身份
【发布时间】:2025-12-20 05:50:06
【问题描述】:

我正在使用 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。

我们将不胜感激。

【问题讨论】:

  • "寻求调试帮助的问题('为什么这段代码不工作?')必须包括期望的行为、特定问题或错误必要的最短代码 在问题本身。没有明确的问题陈述的问题对其他读者没有用处。请参阅:@ 987654321@"
  • 嗨@FrankvanPuffelen 我已经为这个问题添加了更多细节。现在更清楚了吗?

标签: ios firebase flutter firebase-authentication


【解决方案1】:

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

【讨论】:

  • 我已关注所有集成文档,并且我也收到了 OTP。但我面临的问题是在发送 OTP 后没有调用代码发送处理程序。您可以查看我的问题,因为我提供了代码。身份验证流程在 android 中运行,但在 iOS 中遇到此问题。