默认情况下,SwiftUI滑动禁用,电话验证不起作用 [英] SwiftUI swizzling disabled by default, phone auth not working
问题描述
我正在建立一个带有电话号码登录的屏幕.我一遍又一遍地检查并重新创建了该项目,但是,我得到了以下日志:
I am building a screen with phone number login. I checked over and over again and the project is newly created, however, I am getting this log:
7.2.0-[Firebase/Auth] [I-AUT000015] UIApplicationDelegate必须处理远程通知,电话号码身份验证才能正常工作.如果禁用了应用程序委托模糊处理,则需要将UIApplicationDelegate收到的远程通知转发到FIRAuth的canHandleNotificaton:方法.
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.
我确实在文档中读到了有关毛发的信息,但我不知道为什么它似乎被禁用了,我没有禁用它.我已经在应用程序中添加了GoogleServices-Info.plist,我在firebase面板中添加了应用程序apn身份验证密钥.
I did read in the documentation about swizzling and I don't know why it seems to be disabled, I did not disabled it. I have added GoogleServices-Info.plist into the app, I added in firebase panel the app apn auth key.
我在应用程序中的入口点看起来像这样:
My entry point in the app looks like this:
@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
My URL Types property has an entry with the RESERVED_CLIENT_ID
我对这个问题非常绝望.任何想法都受到高度赞赏.
I am very desperate about this problem. Any idea is highly appreciated.
Edit1:
我确实阅读了文档,并尝试在禁用滚动通知的情况下处理通知,但出现了相同的错误:
I did read the documentation and tried to handle notification with swizzling disabled, but I get the same error:
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生命周期实现电话号码验证的方法:
Here's how to implement Phone Number Auth using the new SwiftUI 2 life cycle:
-
创建一个Firebase项目并设置PhoneNumber Auth
Create a Firebase project and set up PhoneNumber Auth
将您的iOS应用添加到Firebase项目,下载并将 GoogleService-Info.plist
添加到您的项目
Add your iOS app to the Firebase project, download and add GoogleService-Info.plist
to your project
在Xcode中,选择应用程序目标并启用以下功能:
In Xcode, select the application target and enable the following capabilities:
- 推送通知
- 背景模式>远程通知
在Apple开发人员门户上创建并注册APNS身份验证密钥
Create and register an APNS authentication key on the Apple developer portal
将密钥上传到Firebase(在Firebase控制台的 Project Settings> Cloud messages 下)
Upload the key to Firebase (under Project Settings > Cloud messaging in the Firebase Console)
将Firebase项目的反向客户端ID添加到您应用的URL方案中
Add the Firebase project's reversed client ID to your app's URL schemes
在您的 Info.plist
中,将 FirebaseAppDelegateProxyEnabled
设置为 NO
按如下所示实施 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
}
}
}
}
为进一步阅读,我建议写这两篇文章:
For further reading, I suggest these two articles I wrote:
这篇关于默认情况下,SwiftUI滑动禁用,电话验证不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!