【发布时间】:2019-09-19 18:23:33
【问题描述】:
我正在尝试使用使用场景(也是新的)的新应用来实现新的 iOS 13 后台任务功能。例子不多,但我发现的不是使用 SceneDelegate,而是所有逻辑都包含在 AppDelegate 中。这会导致问题,因为应用程序进入后台的事件现在是在 SceneDelegate 而不是 AppDelegate 中引发的。
在使用场景时,AppDelegate 中不会触发此方法
func applicationDidEnterBackground(_ application: UIApplication) {
}
此方法在 SceneDelegate 中触发
func sceneDidEnterBackground(_ scene: UIScene) {
}
我无法在 AppDelegate 中为以下方法找到对应的 SceneDelegate 方法,其中所有示例都显示 BGTaskScheduler 注册任务
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
BGTaskScheduler.shared.register(forTaskWithIdentifier: "UNIQUE_ID", using: DispatchQueue.global()) { task in
refreshMethod(task: task as! BGAppRefreshTask)
}
}
我的问题是 SceneDelegate 中是否有一些事件可以在其中注册任务,如果没有,基于场景的应用程序的推荐模式是什么。
【问题讨论】:
-
对此有什么想法吗?关于我为什么被否决的任何反馈?