gpt4 book ai didi

ios - FirebaseApp.configure()线程1 : Signal SIGBART

转载 作者:行者123 更新时间:2023-11-30 11:27:56 25 4
gpt4 key购买 nike

我正在使用 Firebase 和云消息传递做一些事情。

问题是我需要在 FirebaseApp.configure() 之前调用 application.registerForRemoteNotifications() 。我读到它应该可以解决我的问题。

我使用从雇主那里获得的项目,FirebaseApp.configure() 的调用方式如下:

override init() {
super.init()
FirebaseApp.configure()
}

不知道为什么会这样。

并且 application.registerForRemoteNotifications() 在 application(didFinishLaunchingWithOptions) 中被调用。这是我所拥有的:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
// FirebaseApp.configure()
GMSPlacesClient.provideAPIKey("AIzaSyCWMU53OSR4zO28i9e2BsASnda3X1TAS2Y")
GMSServices.provideAPIKey("AIzaSyCWMU53OSR4zO28i9e2BsASnda3X1TAS2Y")
UIApplication.shared.setStatusBarStyle(UIStatusBarStyle.lightContent, animated: true)


UITabBarItem.appearance().setTitleTextAttributes([NSAttributedStringKey.foregroundColor:UIColor.clear], for: .normal)
UITabBarItem.appearance().setTitleTextAttributes([NSAttributedStringKey.foregroundColor:UIColor.clear], for: .selected)




print("Token is ", Messaging.messaging().fcmToken)


Thread.sleep(forTimeInterval: 1.0)

if #available(iOS 10, *) {
UNUserNotificationCenter.current().delegate = self as? UNUserNotificationCenterDelegate

Messaging.messaging().delegate = self

UNUserNotificationCenter.current().requestAuthorization(options: [.badge, .sound, .alert], completionHandler: { (granted, err) in
// application.registerForRemoteNotifications()
})
} else {
let notificationSettings = UIUserNotificationSettings(types: [.badge, .alert, .sound], categories: nil)
UIApplication.shared.registerUserNotificationSettings(notificationSettings)
UIApplication.shared.registerForRemoteNotifications()
}

application.registerForRemoteNotifications()

return true
}

问题是,当我尝试将 FirebaseApp.configure() 放在 application(didFinishLaunchingWithOptions) 的开头时,我得到

Thread 1: signal SIGABRT error.

从控制台我得到:

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'The default FIRApp instance must be configured before the default FIRAuthinstance can be initialized. One way to ensure that is to call [FIRApp configure]; is called in application:didFinishLaunchingWithOptions:.'

我无法理解原因。

最佳答案

首先,FirebaseApp.configure() 必须位于 didFinishLaunchingWithOptions 的第一行

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
FirebaseApp.configure()
...

.

之后,您将完成所有注册工作。

    ...
// Thread.sleep(forTimeInterval: 1.0) // why do you need a sleep here?
if #available(iOS 10, *) {
UNUserNotificationCenter.current().delegate = self as? UNUserNotificationCenterDelegate
Messaging.messaging().delegate = self
UNUserNotificationCenter.current().requestAuthorization(options: [.badge, .sound, .alert], completionHandler: { (granted, err) in
application.registerForRemoteNotifications()
})
} else {
let notificationSettings = UIUserNotificationSettings(types: [.badge, .alert, .sound], categories: nil)
UIApplication.shared.registerUserNotificationSettings(notificationSettings)
UIApplication.shared.registerForRemoteNotifications()
}
return true
}

关于ios - FirebaseApp.configure()线程1 : Signal SIGBART,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50547729/

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