Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS 13 Schedule iOS background tasks

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.
like image 956
Gurjinder Singh Avatar asked Oct 01 '19 14:10

Gurjinder Singh


People also ask

How can we handle background operations in iOS?

Use the BackgroundTasks framework to keep your app content up to date and run tasks requiring minutes to complete while your app is in the background. Longer tasks can optionally require a powered device and network connectivity. Register launch handlers for tasks when the app launches and schedule them as required.

What is background task scheduler?

A class for scheduling task requests that launch your app in the background.

What long running tasks can iOS support in the background?

The answer is simply 600 seconds (10 minutes), reason is provided by the article above.


2 Answers

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

There may be some other reasons. Please visit https://developer.apple.com/documentation/backgroundtasks/bgtaskschedulererrorcode/bgtaskschedulererrorcodeunavailable?language=objc

like image 134
Gurjinder Singh Avatar answered Oct 12 '22 09:10

Gurjinder Singh


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.

like image 36
demosten Avatar answered Oct 12 '22 09:10

demosten