我知道这个问题已经问过几次了,但是没有一个问题能帮助我解决问题。我遵循了文档中提到的所有内容,将Firebase Auth配置为iOS。另外,我正在使用Flutter进行应用程序开发。
这是用于验证电话号码的飞镖代码:
await _auth.verifyPhoneNumber(
phoneNumber: _phoneNumberController.text,
timeout: const Duration(minutes: 2),
verificationCompleted: (user) {
print('verification completed');
},
verificationFailed: (AuthException authException) {
_scaffoldKey.currentState.showSnackBar(SnackBar(
content: Text(
'Phone number verification failed. Code: ${authException.code}. Message: ${authException.message}'),
));
},
codeSent: (String verificationId, [int forceResendingToken]) {
_verificationId = verificationId;
_scaffoldKey.currentState.showSnackBar(SnackBar(
content: const Text(
'Please check your phone for the verification code.'),
));
},
codeAutoRetrievalTimeout: (String verificationId) {
_verificationId = verificationId;
});
当我提供电话号码并进行验证时,它会显示一条错误消息:
如果禁用了应用程序委托模糊处理,则需要将UIApplicationDelegate收到的远程通知转发到FIRAuth的canHandleNotification:方法。
因为我使用的是Flutter,所以我只是将以下代码粘贴到AppDelegate.swift中,我不确定它是否正确。我将在下面粘贴整个课程:
@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?
) -> Bool {
FirebaseApp.configure()
GeneratedPluginRegistrant.register(with: self)
//return super.application(application, didFinishLaunchingWithOptions: launchOptions)
return true
}
override func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
// Pass device token to auth
Auth.auth().setAPNSToken(deviceToken, type: AuthAPNSTokenType.prod)
// Further handling of the device token if needed by the app
// ...
}
override func application(_ application: UIApplication,
didReceiveRemoteNotification notification: [AnyHashable : Any],
fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
if Auth.auth().canHandleNotification(notification) {
completionHandler(UIBackgroundFetchResult.noData)
return
}
// This notification is not auth related, developer should handle it.
}
// For iOS 9+
override func application(_ application: UIApplication, open url: URL,
options: [UIApplicationOpenURLOptionsKey : Any]) -> Bool {
if Auth.auth().canHandle(url) {
return true
}
// URL not auth related, developer should handle it.
return true;
}
}
到目前为止,我已经尝试过:
版本信息:
我可能会错过一些信息,但我会尽力包括所有必要的内容。
任何解决此问题的方法/想法都将不胜感激。
谢谢。