如何在 iOS 14(SwiftUI) Widget Extension 中初始化 Facebook SDK?
Posted
技术标签:
【中文标题】如何在 iOS 14(SwiftUI) Widget Extension 中初始化 Facebook SDK?【英文标题】:How to initialise Facebook SDK in iOS 14(SwiftUI) Widget Extension? 【发布时间】:2021-05-20 07:56:31 【问题描述】:如何在 ios 14(SwiftUI) 小部件扩展中初始化 Facebook SDK?我需要在哪里调用下面的方法?
ApplicationDelegate.shared.application( application, didFinishLaunchingWithOptions: launchOptions)
我的最终目标是从我的小部件中调用 GraphRequest。而根据documentation,调用graph request需要先初始化Facebook SDK。
提前致谢!
【问题讨论】:
【参考方案1】:HackingWithSwift 有一个解决方案 https://www.hackingwithswift.com/quick-start/swiftui/how-to-add-an-appdelegate-to-a-swiftui-app
它在主视图中使用 AppDelegate
【讨论】:
【参考方案2】:只是一个小提示: 如果您正在从头开始编写应用程序并认为您将需要 Appdelegate 逻辑,您可以在开始时选择:
你在哪里得到:
@main
class AppDelegate: UIResponder, UIApplicationDelegate
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool
// Override point for customization after application launch.
return true
// MARK: UISceneSession Lifecycle
func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration
// Called when a new scene session is being created.
// Use this method to select a configuration to create the new scene with.
return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>)
// Called when the user discards a scene session.
// If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
// Use this method to release any resources that were specific to the discarded scenes, as they will not return.
【讨论】:
以上是关于如何在 iOS 14(SwiftUI) Widget Extension 中初始化 Facebook SDK?的主要内容,如果未能解决你的问题,请参考以下文章
SwiftUI禁止用户关闭sheet弹出视图在iOS14.6+失效的巧妙解决
SwiftUI禁止用户关闭sheet弹出视图在iOS14.6+失效的巧妙解决
如何在最新的 iOS 14 中仅在 swiftui 中舍入滚动视图的顶角
iOS 14.0 之后如何解决 SwiftUI 中 RealmSwift.App 和 SwiftUI.App 的冲突?