[英]Flutter-Firebase phone Auth always returns Token mismatch on iOS
I'm trying to use phone Authentication and it's working as expected on Android, but on iOS I always get Token mismatch and don't receive a code.我正在尝试使用电话身份验证,它在 Android 上按预期工作,但在 iOS 上我总是遇到令牌不匹配并且没有收到代码。
other Firebase services like cloud firestore and email Auth are working fine on iOS.其他 Firebase 服务(如 cloud firestore 和电子邮件身份验证)在 iOS 上运行良好。
I made sure of the following:我确定了以下几点:
-APN key is added in Firebase - 在 Firebase 中添加了 APN 密钥
-Google Services file is updated -Google 服务文件已更新
-Background Modes and Push Notification capabilities are on - 后台模式和推送通知功能开启
the error message is from PhoneVerificationFailed错误消息来自 PhoneVerificationFailed
Future<void> _verifyPhoneNumber() async {
setState(() {
_message = '';
});
final PhoneVerificationCompleted verificationCompleted =
(AuthCredential phoneAuthCredential) async {
await _auth.signInWithCredential(phoneAuthCredential);
setState(() {
_message = 'Received phone auth credential: $phoneAuthCredential';
});
};
final PhoneVerificationFailed verificationFailed =
(AuthException authException) {
setState(() {
_message = '********************\n\n'
'Phone number verification failed. Code: ${authException.code}.'
'\n Message: ${authException.message}'
'\n\n********************';
});
};
final PhoneCodeSent codeSent =
(String verificationId, [int forceResendingToken]) async {
_verificationId = verificationId;
setState(() {
_message = 'waiting for code';
//waitingCode = true;
});
};
final PhoneCodeAutoRetrievalTimeout codeAutoRetrievalTimeout =
(String verificationId) {
_verificationId = verificationId;
};
try {
await _auth.verifyPhoneNumber(
phoneNumber: number,
timeout: const Duration(seconds: 30),
verificationCompleted: verificationCompleted,
verificationFailed: verificationFailed,
codeSent: codeSent,
codeAutoRetrievalTimeout: codeAutoRetrievalTimeout);
} catch (e) {
print('Error is $e');
}
}
and I'm getting these messages from log我从日志中收到这些消息
Userinfo {
"com.google.firebase.auth" = {
warning = "This fake notification should be forwarded to Firebase Auth.";
};
}
UserDate : {
"com.google.firebase.auth" = {
warning = "This fake notification should be forwarded to Firebase Auth.";
};
}
UserDate Json : {
"com.google.firebase.auth" : {
"warning" : "This fake notification should be forwarded to Firebase Auth."
}
}
flutter:
TRUE
flutter: Call Back {
"com.google.firebase.auth" : {
"warning" : "This fake notification should be forwarded to Firebase Auth."
}
}
I understand it's too late in answering this.我明白现在回答这个为时已晚。 But I also faced the same error recently.
但我最近也遇到了同样的错误。 I fixed the issue on iOS.
我在 iOS 上解决了这个问题。 Your entire configuration must be valid.
您的整个配置必须有效。 There are two settings you need to make.
您需要进行两项设置。
Remove any method swizzling variable from GoogleService-info.plist ie remove FirebaseAppDelegateProxyEnabled
property from plist从 GoogleService-info.plist 中删除任何方法 swizzling 变量,即从 plist 中删除
FirebaseAppDelegateProxyEnabled
属性
In AppDelegate.swift, override this method and set the following在 AppDelegate.swift 中,覆盖此方法并设置以下内容
func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) { Messaging.messaging().apnsToken = deviceToken } func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) { Messaging.messaging().apnsToken = deviceToken }
It is mentioned at https://firebase.google.com/docs/cloud-messaging/ios/client#token-swizzle-disabled它在https://firebase.google.com/docs/cloud-messaging/ios/client#token-swizzle-disabled 中提到
I am using firebase_messaging: ^6.0.16
and the above settings worked我正在使用
firebase_messaging: ^6.0.16
并且上述设置有效
Changing the Firebase Auth version from 0.14.0 to将 Firebase Auth 版本从 0.14.0 更改为
firebase_auth:
git:
url: https://github.com/collinjackson/plugins.git
ref: 441417c2fed0ff26bf84a49ab2c5ffd2aa5487de
path: packages/firebase_auth
fixed my issue.修复了我的问题。 see https://github.com/flutter/flutter/issues/35267 for more details
有关更多详细信息,请参阅https://github.com/flutter/flutter/issues/35267
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.