Swift3 - 调试时后台获取崩溃
Swift3 - Background Fetch Crash on Debug
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 上崩溃我没有问题。
根据你上面的描述,我在我的项目中试过了,但它工作正常,performFetchWithCompletionHandler
也在后台工作。
首先我尝试不添加此 属性,但未调用 performFetchWithCompletionHandler。所以,尝试在 info.plist 文件
中添加这个
<key>UIBackgroundModes</key>
<array>
<string>fetch</string>
</array>
它将解决我的问题
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 上崩溃我没有问题。
根据你上面的描述,我在我的项目中试过了,但它工作正常,performFetchWithCompletionHandler
也在后台工作。
首先我尝试不添加此 属性,但未调用 performFetchWithCompletionHandler。所以,尝试在 info.plist 文件
中添加这个 <key>UIBackgroundModes</key>
<array>
<string>fetch</string>
</array>
它将解决我的问题