android - Firebase 电话身份验证 (Flutter) 在某些 iOS 设备中不起作用
问题描述
我已经使用 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
解决方案
尝试将 REVERSE_CLIENT_ID 自定义 URL 方案添加到您的 Xcode 项目。
根据火力基地文件:
iOS 设置注意事项:应用验证可能会使用 APN,如果使用模拟器(其中 APN 不起作用)或未在您使用的设备上设置 APN,则必须将 URL 方案设置为 GoogleServices-Info.plist 文件中的 REVERSE_CLIENT_ID。
如何将自定义 URL 方案添加到您的 Xcode 项目:
- 打开您的项目配置:双击左侧树视图中的项目名称。从 TARGETS 部分中选择您的应用程序,然后选择 Info 选项卡,然后展开 URL Types 部分。
- 单击 + 按钮,并为您的反向客户端 ID 添加 URL 方案。要查找此值,请打开 GoogleService-Info.plist 配置文件,然后查找 REVERSED_CLIENT_ID 键。复制该键的值,并将其粘贴到配置页面上的 URL 方案框中。将其他字段留空。
来自这里的参考资料:
推荐阅读
- java - .classpath 文件阻止了 git rebase
- artifactory - JFrog CLI 无法为 JFrog Artifactory 中的工件设置属性作为第一个属性名称并使用 SSH 密钥示例进行多属性搜索
- laravel-5 - 插入一对一多态关系laravel 5时,“字段列表”中的未知列“imageable_type”
- r - Xaringan 情节不渲染:网站正在减慢您的浏览器您想做什么
- java - 无法使用 Apache POI 删除行,因为单元格包含电子邮件地址
- css - 如何显示被其他div覆盖的div
- regex - 带有正则表达式的 Makefile 模式规则
- scala - 匹配运行计算的结果在 for comprehension 中无效
- sql-server - 尝试通过声明数据在 T-SQL 中排序时出错
- python - 我如何知道文件是否已完成复制?