22

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.
Gurjinder Singh
  • 9,221
  • 1
  • 66
  • 58

10 Answers10

42

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.

demosten
  • 3,301
  • 2
  • 25
  • 18
40

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

Gurjinder Singh
  • 9,221
  • 1
  • 66
  • 58
8

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.

Jeremy Caney
  • 7,102
  • 69
  • 48
  • 77
eric.rl
  • 151
  • 1
  • 7
  • Just want to add that for it to work best you should use the "com.COMPANY.IDNAME" format for your identifiers – Some guy May 18 '23 at 22:04
4

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

iCoder86
  • 1,874
  • 6
  • 26
  • 46
2

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

James Chan
  • 97
  • 2
  • 12
2

I think this is because that your mobile turn the bg refresh off!!!!!!!

Lyman Lai
  • 191
  • 1
  • 4
1

In case of BGTaskSchedulerErrorDomain error 3, I didn't add below

<array>
    <string>com.shiny.job</string>
    <string>com.shiny.jobpower</string>
    <string>com.shiny.jobnet</string>
    <string>com.shiny.jobpowernet</string>
</array>```
Div
  • 72
  • 6
0

Just check the Background Modes has been added to the target Capabilities and that Background fetch and Background processing options are selected

Miniapps
  • 292
  • 3
  • 3
0

According to https://developer.apple.com/documentation/backgroundtasks/bgtaskschedulererrorcode/bgtaskschedulererrorcodeunavailable?language=objc, this error usually occurs for one of three reasons:

  • The user has disabled background refresh in settings.
  • The app is running on Simulator which doesn’t support background processing.
  • The keyboard extension either hasn’t set RequestsOpenAccess to YES in The Info.plist File, or the user hasn’t granted open access.
  • The extension type isn’t able to schedule background tasks.
Antenehs
  • 336
  • 1
  • 7
0

check you Appdelegate.swift is including WorkmanagerPlugin.registerTask(withIdentifier: "your.task.id")

Eray Hamurlu
  • 657
  • 7
  • 9