gpt4 book ai didi

ios - flutter:如果 app delegate swizzling 被禁用,UIApplicationDelegate 收到的远程通知需要转发到 FIRAuth 的

转载 作者:行者123 更新时间:2023-11-28 07:24:14 33 4
gpt4 key购买 nike

当我想在 firebase 中使用短信验证时,应用程序仅在 iOS 上失败

APN 证书已在 firebase 上配置,FirebaseAppDelegateProxyEnabledInfo.plist 中为 NO。错误发生在 verifyPhoneNumber 方法期间。

这是flutter医生

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel unknown, v1.7.0, on Mac OS X 10.14.5 18F132, locale en-PE)

[✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
[✓] Xcode - develop for iOS and macOS (Xcode 10.2.1)
[✓] iOS tools - develop for iOS devices
[✓] Android Studio (version 3.4)
[!] IntelliJ IDEA Ultimate Edition (version 2019.1)
✗ Flutter plugin not installed; this adds Flutter specific functionality.
✗ Dart plugin not installed; this adds Dart specific functionality.
[✓] VS Code (version 1.36.1)
[✓] Connected device (1 available)

这是我的代码

void sendSms(String fullNumber) {
FirebaseAuth.instance.verifyPhoneNumber(
phoneNumber: fullNumber,
timeout: Duration(minutes: 1),
verificationCompleted: (AuthCredential phoneAuthCredential) async {
_smsController?.add('loading');
FirebaseUser firebaseUser = await FirebaseAuth.instance
.signInWithCredential(phoneAuthCredential);
_verifyUser(firebaseUser);
},
verificationFailed: (err) {
print(err.message);
print(err.code);
_smsController?.add('UNKNOWN_ERROR');
},
codeSent: (verificationId, [forceResendingToken]) {
_verificationId = verificationId;
_smsController?.add('code_sent');
},
codeAutoRetrievalTimeout: (verificationId) {},
);
}

错误信息:

flutter:如果禁用应用程序委托(delegate)调配,UIApplicationDelegate 收到的远程通知需要转发到 FIRAuth 的 canHandleNotificaton: 方法。

flutter: verifyPhoneNumberError

最佳答案

最佳可用解决方案AppDelegate.swift:

import UIKit
import Flutter
import FirebaseAuth
import FirebaseMessaging

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [.
UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
if #available(iOS 10.0, *) {
UNUserNotificationCenter.current().delegate = self
}

GeneratedPluginRegistrant.register(with: self)
return super.application(application, didFinishLaunchingWithOptions:
launchOptions)
}

// https://firebase.google.com/docs/auth/ios/phone-auth#appendix:-using-phone-sign-in-without-swizzling
// https://firebase.google.com/docs/cloud-messaging/ios/client#token-swizzle-disabled
override func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
// Pass device token to auth
Auth.auth().setAPNSToken(deviceToken, type: .unknown)

// Pass device token to messaging
Messaging.messaging().apnsToken = deviceToken

return super.application(application, didRegisterForRemoteNotificationsWithDeviceToken: deviceToken)
}

// https://firebase.google.com/docs/auth/ios/phone-auth#appendix:-using-phone-sign-in-without-swizzling
// https://firebase.google.com/docs/cloud-messaging/ios/receive#handle-swizzle
override func application(_ application: UIApplication,
didReceiveRemoteNotification notification: [AnyHashable : Any],
fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
// Handle the message for firebase auth phone verification
if Auth.auth().canHandleNotification(notification) {
completionHandler(.noData)
return
}

// Handle it for firebase messaging analytics
if ((notification["gcm.message_id"]) != nil) {
Messaging.messaging().appDidReceiveMessage(notification)
}

return super.application(application, didReceiveRemoteNotification: notification, fetchCompletionHandler: completionHandler)
}

// https://firebase.google.com/docs/auth/ios/phone-auth#appendix:-using-phone-sign-in-without-swizzling
override func application(_ application: UIApplication, open url: URL,
options: [UIApplication.OpenURLOptionsKey : Any]) -> Bool {
// Handle auth reCAPTCHA when silent push notifications aren't available
if Auth.auth().canHandle(url) {
return true
}

return super.application(application, open: url, options: options)
}
}

关于ios - flutter:如果 app delegate swizzling 被禁用,UIApplicationDelegate 收到的远程通知需要转发到 FIRAuth 的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57048800/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com