【问题标题】:BackgroundTask iOS 13 Swift with ScenesBackgroundTask iOS 13 Swift 与场景
【发布时间】: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 中是否有一些事件可以在其中注册任务,如果没有,基于场景的应用程序的推荐模式是什么。

【问题讨论】:

  • 对此有什么想法吗?关于我为什么被否决的任何反馈?

标签: swift ios13


【解决方案1】:

AppDelegate.didFinishLaunchingWithOptions 仍会在应用启动时调用,即使您有 SceneDelegate。所以你应该继续用那个方法注册你的后台任务。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-01-04
    • 2020-01-30
    • 2020-01-30
    • 1970-01-01
    • 2020-04-21
    • 1970-01-01
    • 2017-08-20
    • 2019-10-28
    相关资源
    最近更新 更多