meaning-matters
meaning-matters

Reputation: 22946

Background Fetch not working on all devices

In a test device that's never been used for development, iOS Background Fetch works fine, continuing during the night.

But on two other devices, used for development, the fetches sometimes occur, but often don't, not even during the night.

Did anyone experience the same odd behaviour? Do fetches occur only when there's Wi-Fi available, or are there other factors I might be missing that influences fetch behaviour?

Upvotes: 0

Views: 666

Answers (2)

meaning-matters
meaning-matters

Reputation: 22946

Turned out to be the following: I had data protection switched on which required the iPhone to be unlocked before my web credentials could be read.

Before doing the background fetch, I checked if the app was logged in by checking these credentials. This check failed because the keychain was locked.

The two iPhones for which background fetch worked only sporadically had passcode protection enabled, while the iPhone for which it always worked had passcode protection disabled.

I hope this helps other people. Here's a good article discussing my issue, which I found after I painfully sorted it out myself.

Upvotes: 0

Emel Elias
Emel Elias

Reputation: 572

Enabling this mode is not a guarantee that the system will give your app any time to perform background fetches. The system must balance your app’s need to fetch content with the needs of other apps and the system itself. After assessing that information, the system gives time to apps when there are good opportunities to do so.

Also please confirm you are using NSURLSession

When downloading any content, it is recommended that you use the NSURLSession class to initiate and manage your downloads. For information about how to use this class to manage upload and download tasks, see URL Session Programming Guide.

https://developer.apple.com/library/content/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/BackgroundExecution/BackgroundExecution.html

Upvotes: 1

Related Questions