SwiftUI New App生命周期如何连接Facebook SDK
SwiftUI New App lifecycle how to connect the Facebook SDK
我正在使用 Firebase 和 Facebook 身份验证创建 SwiftUI 应用程序,但我遇到了基本设置问题。在 Facebook for Developers 上有教程如何设置应用程序和替换整个 AppDelegate class:
import UIKit
import FBSDKCoreKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
ApplicationDelegate.shared.application(
application,
didFinishLaunchingWithOptions: launchOptions
)
return true
}
func application(
_ app: UIApplication,
open url: URL,
options: [UIApplication.OpenURLOptionsKey : Any] = [:]
) -> Bool {
ApplicationDelegate.shared.application(
app,
open: url,
sourceApplication: options[UIApplication.OpenURLOptionsKey.sourceApplication] as? String,
annotation: options[UIApplication.OpenURLOptionsKey.annotation]
)
}
}
我的问题是,当我对 App 结构使用新的生命周期时,如何做同样的事情:
import SwiftUI
import Firebase
import FBSDKCoreKit
@main
struct SplitApp: App {
init() {
FirebaseApp.configure()
}
var body: some Scene {
WindowGroup {
WelcomeView()
}
}
}
我必须使用旧的生命周期吗?谢谢!
将 UIApplicationDelegateAdaptor 添加到您的 SwiftUI 应用程序
import SwiftUI
import Firebase
@main
struct SplitApp: App {
@UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
var body: some Scene {
WindowGroup {
WelcomeView()
}
}
class AppDelegate: NSObject, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
ApplicationDelegate.shared.application(
application,
didFinishLaunchingWithOptions: launchOptions
)
FirebaseApp.configure()
return true
}
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
ApplicationDelegate.shared.application(
app,
open: url,
sourceApplication: options[UIApplication.OpenURLOptionsKey.sourceApplication] as? String,
annotation: options[UIApplication.OpenURLOptionsKey.annotation]
)
}
}
}
我正在使用 Firebase 和 Facebook 身份验证创建 SwiftUI 应用程序,但我遇到了基本设置问题。在 Facebook for Developers 上有教程如何设置应用程序和替换整个 AppDelegate class:
import UIKit
import FBSDKCoreKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
ApplicationDelegate.shared.application(
application,
didFinishLaunchingWithOptions: launchOptions
)
return true
}
func application(
_ app: UIApplication,
open url: URL,
options: [UIApplication.OpenURLOptionsKey : Any] = [:]
) -> Bool {
ApplicationDelegate.shared.application(
app,
open: url,
sourceApplication: options[UIApplication.OpenURLOptionsKey.sourceApplication] as? String,
annotation: options[UIApplication.OpenURLOptionsKey.annotation]
)
}
}
我的问题是,当我对 App 结构使用新的生命周期时,如何做同样的事情:
import SwiftUI
import Firebase
import FBSDKCoreKit
@main
struct SplitApp: App {
init() {
FirebaseApp.configure()
}
var body: some Scene {
WindowGroup {
WelcomeView()
}
}
}
我必须使用旧的生命周期吗?谢谢!
将 UIApplicationDelegateAdaptor 添加到您的 SwiftUI 应用程序
import SwiftUI
import Firebase
@main
struct SplitApp: App {
@UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
var body: some Scene {
WindowGroup {
WelcomeView()
}
}
class AppDelegate: NSObject, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
ApplicationDelegate.shared.application(
application,
didFinishLaunchingWithOptions: launchOptions
)
FirebaseApp.configure()
return true
}
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
ApplicationDelegate.shared.application(
app,
open: url,
sourceApplication: options[UIApplication.OpenURLOptionsKey.sourceApplication] as? String,
annotation: options[UIApplication.OpenURLOptionsKey.annotation]
)
}
}
}