gpt4 book ai didi

默认情况下禁用 SwiftUI swizzling,电话身份验证不起作用

转载 作者:行者123 更新时间:2023-12-04 16:25:27 25 4
gpt4 key购买 nike

我正在构建一个带有电话号码登录的屏幕。我一遍又一遍地检查,该项目是新创建的,但是,我收到了以下日志:

7.2.0 - [Firebase/Auth][I-AUT000015] The UIApplicationDelegate must handle remote notification for phone number authentication to work.If app delegate swizzling is disabled, remote notifications received by UIApplicationDelegate need to be forwarded to FIRAuth's canHandleNotificaton: method.


我确实阅读了有关 swizzling 的文档,但我不知道为什么它似乎被禁用了,我没有禁用它。我已将 GoogleServices-Info.plist 添加到应用程序中,我在 firebase 面板中添加了应用程序 apn auth key 。
我在应用程序中的入口点如下所示:
@main
struct partidulverdeApp: App {

init() {
FirebaseApp.configure()
}

var body: some Scene {
WindowGroup {
MainView()
.onOpenURL { url in
Auth.auth().canHandle(url.absoluteURL)
}
}
}
}
我的 URL 类型属性有一个带有 RESERVED_CLIENT_ID 的条目
我对这个问题非常绝望。任何想法都受到高度赞赏。
编辑1:
我确实阅读了文档并尝试在禁用 swizzling 的情况下处理通知,但我遇到了同样的错误:
class AppDelegate: NSObject, UIApplicationDelegate {

func application(_ application: UIApplication,
didReceiveRemoteNotification notification: [AnyHashable : Any],
fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
if Auth.auth().canHandleNotification(notification) {
completionHandler(.noData)
return
}

}

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
print("Your code here")
return true
}
}

@main
struct partidulverdeApp: App {

@UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate

init() {
FirebaseApp.configure()
}

var body: some Scene {
WindowGroup {
MainView()
.onOpenURL { url in
Auth.auth().canHandle(url.absoluteURL)
}
}
}
}

最佳答案

以下是如何使用新的 SwiftUI 2 生命周期实现电话号码身份验证:

  • 创建 Firebase 项目并设置 PhoneNumber Auth
  • 将您的 iOS 应用添加到 Firebase 项目,下载并添加 GoogleService-Info.plist到你的项目
  • 在 Xcode 中,选择应用程序目标并启用以下功能:
  • 推送通知
  • 后台模式 > 远程通知

  • 在 Apple 开发人员门户上创建并注册 APNS 身份验证 key
  • 将 key 上传到 Firebase(在 Firebase 控制台中的项目设置 > 云消息传递下)
  • 将 Firebase 项目的反向客户端 ID 添加到您应用的网址方案
  • 在您的 Info.plist , 设置 FirebaseAppDelegateProxyEnabledNO
  • 实现 AppDelegate如下:

  • class AppDelegate: NSObject, UIApplicationDelegate {
    func application(_ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
    FirebaseApp.configure()
    print("SwiftUI_2_Lifecycle_PhoneNumber_AuthApp application is starting up. ApplicationDelegate didFinishLaunchingWithOptions.")
    return true
    }

    func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
    print("\(#function)")
    Auth.auth().setAPNSToken(deviceToken, type: .sandbox)
    }

    func application(_ application: UIApplication, didReceiveRemoteNotification notification: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
    print("\(#function)")
    if Auth.auth().canHandleNotification(notification) {
    completionHandler(.noData)
    return
    }
    }

    func application(_ application: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any]) -> Bool {
    print("\(#function)")
    if Auth.auth().canHandle(url) {
    return true
    }
    return false
    }
    }

    @main
    struct SwiftUI_2_Lifecycle_PhoneNumber_AuthApp: App {
    @UIApplicationDelegateAdaptor(AppDelegate.self) var delegate

    var body: some Scene {
    WindowGroup {
    ContentView()
    .onOpenURL { url in
    print("Received URL: \(url)")
    Auth.auth().canHandle(url) // <- just for information purposes
    }
    }
    }
    }

    为了进一步阅读,我推荐我写的这两篇文章:
  • Firebase and the new SwiftUI 2 Application Life Cycle
  • The Ultimate Guide to the SwiftUI 2 Application Life Cycle
  • 关于默认情况下禁用 SwiftUI swizzling,电话身份验证不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65409563/

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