1
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    print(UIApplicationBackgroundFetchIntervalMinimum)
    UIApplication.shared.setMinimumBackgroundFetchInterval(UIApplicationBackgroundFetchIntervalMinimum)
    return true
}

func application(_ application: UIApplication, performFetchWithCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
    completionHandler(.newData)
}

这是我的代码,当我在 XCode 中调试 > 模拟后台获取我的应用程序崩溃时,无缘无故。我在功能>后台模式>后台获取中激活...有什么想法吗?

它仅在模拟器中的 iPhone 上崩溃我没有问题。

4

1 回答 1

3

根据您的上述描述,我在我的项目中尝试过它,但它工作正常并且performFetchWithCompletionHandler也在后台工作。

首先,我尝试不添加此属性,但未调用 performFetchWithCompletionHandler。因此,尝试将其添加到 info.plist 文件中

 <key>UIBackgroundModes</key>
    <array>
        <string>fetch</string>
    </array>

它将解决我的问题

于 2016-10-24T11:57:56.073 回答