iOS 13 Schedule iOS background tasks

孤者浪人 提交于 2020-06-09 12:17:59

问题


I am implementing BackgroundTasks Framework for updating the data. But I got the below issue

Could not schedule refreshApp: Error Domain=BGTaskSchedulerErrorDomain Code=1 "(null)"
Could not schedule data featch: Error Domain=BGTaskSchedulerErrorDomain Code=1 "(null)"
2019-10-01 19:19:32.550320+0530 SOBackgroundTask[34131:1129470] Can't end BackgroundTask: no background task exists with identifier 3 (0x3), or it may have already been ended. Break in UIApplicationEndBackgroundTaskError() to debug.

回答1:


Here are possible error codes for Domain=BGTaskSchedulerErrorDomain extracted from ObjC headers with some explanation.

BGTaskSchedulerErrorCodeUnavailable = 1 // Background task scheduling functionality is not available for this app/extension. Background App Refresh may have been disabled in Settings.

BGTaskSchedulerErrorCodeTooManyPendingTaskRequests = 2 // The task request could not be submitted because there are too many pending task requests of this type. Cancel some existing task requests before trying again.

BGTaskSchedulerErrorCodeNotPermitted = 3 // The task request could not be submitted because the appropriate background mode is not included in the UIBackgroundModes array, or its identifier was not present in the BGTaskSchedulerPermittedIdentifiers array in the app's Info.plist.




回答2:


The solution is to run on a device. I was running on simulator. However, It was showing Background App Refresh has been enable in Settings while running on simulator.




回答3:


I have tested on real device(iOS13.2, and iOS13.2.2), but it's same result.

Error Domain=BGTaskSchedulerErrorDomain Code=2 "(null)" Can't end BackgroundTask: no background task exists with identifier 37 (0x25), or it may have already been ended. Break in UIApplicationEndBackgroundTaskError() to debug.

Error Domain=BGTaskSchedulerErrorDomain Code=1 "(null)" Can't end BackgroundTask: no background task exists with identifier 113 (0x71), or it may have already been ended. Break in UIApplicationEndBackgroundTaskError() to debug.

It seems that there is still exist bug.

https://forums.developer.apple.com/thread/121990




回答4:


Please check if you miss registering BGTaskSchedulerPermittedIdentifiers in info.plist file of your project.




回答5:


For:

BGTaskSchedulerErrorDomain error 3

Check inside the project’s .xcodeproj file for the appropriate target. Then go to the info tab and Custom iOS Target Properties and check that the permitted background task scheduler identifiers (BGTaskSchedulerPermittedIdentifiers) are added.

This solved my problem when adding BackgroundTasks to an existing project.



来源:https://stackoverflow.com/questions/58187320/ios-13-schedule-ios-background-tasks

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!