如何使Firebase与macOS应用程序兼容?



我已经按照步骤使用Firebase为我正在创建的macOS应用程序。我粘贴:

class AppDelegate: NSObject, UIApplicationDelegate {
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
FirebaseApp.configure()

return true
}
}

到我的代码中,但是它给了UIApplicationDelegate错误。

我认为这是因为我需要一个macOS应用程序的NS,但当我做NSApplicationDelegate时,它给出了错误"'LaunchOptionsKey'不是类'AppKit.NSApplication'的成员类型"。我该如何解决这个问题?

作为macOS的应用程序意味着你将没有任何UI*类。

在macOS中,app委托是NSApplicationDelegateapplicationDidFinishLaunching委托方法的签名为func applicationDidFinishLaunching(_ notification: Notification)

所以你的代码变成了这样的:
class AppDelegate: NSObject, NSApplicationDelegate {
func applicationDidFinishLaunching(_ notification: Notification) {
FirebaseApp.configure()
}
}

这实际上不是使Firebase与macOS兼容的问题。这更多的是使用AppKit代码而不是UIKit代码的问题。此处Firebase代码与此无关。

相关内容

最新更新