Swift3 - Background Fetch Crash on Debug

时间:2016-10-20 20:01:05

标签: ios swift3 ios10 background-fetch

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)
}

This is my code and when I Debug in XCode > Simulate background fetch my app crash without reason. I activated in Capabilities>Background modes>Background fetch... any ideas?

It crash only on iPhone in simulator I don't have problems.

1 个答案:

答案 0 :(得分:3)

根据您的上述说明,我在我的项目中尝试了它,但它工作正常,performFetchWithCompletionHandler也在后台工作。

首先我尝试不添加此属性,但未调用performFetchWithCompletionHandler。所以,尝试在info.plist文件中添加它

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

它将解决我的问题