我正在尝试用一个新的应用程序实现新的iOS 13后台任务功能,该应用程序利用了场景(也是新的)。没有太多的例子,但我找到的那些并没有使用SceneDelegates,而是所有的逻辑都包含在AppDelegate中。这会导致问题,因为应用程序进入后台的事件现在在SceneDelegate中引发,而不是在AppDelegate中引发。
使用场景时,此方法不会在AppDelegate中触发
func applicationDidEnterBackground(_ application: UIApplication) {
}此方法在SceneDelegate中触发
func sceneDidEnterBackground(_ scene: UIScene) {
}在所有示例都显示BGTaskScheduler注册任务的AppDelegate中,我找不到与以下方法对应的SceneDelegate方法
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中是否有一些事件可以注册任务,如果没有,基于场景的应用程序的推荐模式是什么。
发布于 2020-01-12 20:41:13
即使你有一个SceneDelegate,在应用启动时仍然会调用AppDelegate.didFinishLaunchingWithOptions。因此,您应该继续使用该方法注册后台任务。
https://stackoverflow.com/questions/58016967
复制相似问题