Background fetch in iOS 11.x

Has any success in using background fetch feature in iOS 11.x?


I have made all the right settings but it is not working.

// this method never gets called....

public func application(_ application: UIApplication, performFetchWithCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {


}

Replies

Has any success in using background fetch feature in iOS 11.x?

Is your problem new on iOS 11? That is, do you have existing code that worked on iOS 10? Or is this new code that you’ve only tested on iOS 11?

Testing background fetch is tricky because the OS decides when to run your app to do a background fetch, and the algorithm is uses is complex. For initial bring up I recommend that you look at the Launch due to background fetch event checkbox in the Options tab of the scheme editor. Once you get past that the only good testing option I’m aware of is to add appropriate logging to your app and then run it in real world conditions.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Hi Eskimo,


This is a brand new code which I am testing.


If I run it using the "simulate background fetch", the code gets executed. However, I couldn't go further executing it using - "Launch due to a background fetch event". It comes back with - "iPad has denied the launch request."

The log shows - "error: failed to launch process /Developer/usr/bin/debugserver: timed out trying to launch app"


I am not quite sure why it times out.


Thanks,


Dankira.

Having exactly the same issue, using the "Launch due to a background fetch event" option worked perfectly until earlier this week (might stopped last week), getting the `denied launch request` error.


I'm pretty sure it worked before upgrading the test device to 11.1.2, I'll try with 11.2 beta and see what happens.

@dankira - I just confirmed that simulating launch due to background fetch works on 11.0.3, 11.2 beta didn't work as well so I restored the test device to 11.0.3 and voila! no more denied launch request.


Hopefully Apple will fix this in 11.1.2 and 11.2 beta so developers can continue to test the feature. (bug 35665522)


Best regards,

Nimrod

@Nimrod - Thanks for confirming this. I wish apple would fix sooner.


Thanks,


Dankira.

The “denied the launch request” issue seems very much like a bug. [Thanks to nimrodgutman for filing a bug report (r. 35665522) about it.] One of my colleagues here in DTS is looking into this on behalf of another developer. We won’t know more until folks get back to work after the US Thanksgiving break.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Is there any update on this? I am hitting this issue in the release versions of iOS 11.2 and Xcode 9.2


Thank you

Is there any update on this?

Not really. The bug is still being looked at by iOS Engineering.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Is there any update on this now?

Is there any update on this now?

From my perspective, no )-:

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

From my perspective, no )-:

Ah, some good news. All of the bugs about this got dup’d to a single bug (r. 36667814) that is reported as fixed in iOS 11.3 beta 3 (15E5189f). Please take that build for a spin and let us know if you still have problems.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Still having problems here with 11.3 (15E5216a). In the device log:


Mar 20 07:37:14 iPad-Mini dasd(DuetActivitySchedulerDaemon)[92] <Notice>: com.apple.fetch.com.delphiworlds.BackgroundFetchDemo:836C17:[

{name: ApplicationPolicy, policyWeight: 50.000, response: {Decision: Can Proceed, Score: 0.50}}

{name: DeviceActivityPolicy, policyWeight: 5.000, response: {Decision: Can Proceed, Score: 0.05}}

] sumScores:51.560000, denominator:81.310000, FinalDecision: Can Proceed FinalScore: 0.634116}

Mar 20 07:37:14 iPad-Mini dasd(DuetActivitySchedulerDaemon)[92] <Notice>: 'com.apple.fetch.com.delphiworlds.BackgroundFetchDemo:836C17' CurrentScore: 0.634116, ThresholdScore: 0.736189 DecisionToRun:0


The CurrentScore never gets above the ThresholdScore. Is this a bug or do I need to do something else to allow it to run?

The

CurrentScore
never gets above the
ThresholdScore
.

This is a very different issue than the one discussed up thread, that is, a bug whose symptoms are a “denied the launch request” error (r. 35665522). And it actually brings me back to something I wrote right at the beginning of this thread:

Testing background fetch is tricky because the OS decides when to run your app to do a background fetch, and the algorithm is uses is complex. For initial bring up I recommend that you look at the “Launch due to background fetch event” checkbox in the Options tab of the scheme editor.

Is that working for you?

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

"Is that working for you?"


Since I'm not using Xcode, no. I note from another thread:
"Debugging background fetch in production involves:

  • Comprehensive logging
  • Running the app frequently, so that the system decides to give it background fetch time
  • After about a week, looking at the logs to see if your app got background fetch time, how much it got, and how it handled those event"

How comprehensive is "comprehensive"? I'm logging some of my apps activity, including when performFetchWithCompletionHandler is called, but that's *never* anyway, because iOS seems to refuse to run it.

Why would the app have to be run "frequently" in order to receive background fetch time? A potential scenario: The user runs the app; they decide to put it in the background soon after; iOS decides not to allow any background fetch, thus potentially degrading the users experience of the app.

How many people have a week to spend in order to see if their background fetch is working?

Since I'm not using Xcode, no.

You’re not using Xcode at all? Or not using it for this test?

How many people have a week to spend in order to see if their background fetch is working?

That depends on what you mean by “working”. If your goal is to test your background fetch handling code, most folks rely on Xcode’s Simulate Background Fetch feature. If you want to see how this works in practice, then the only thing you can do is use the app for extended periods of time because that’s how your users will be using it.

Why would the app have to be run "frequently" in order to receive background fetch time?

iOS has a resource management subsystem that keeps track of user activity patterns and uses that to guide system behaviour. For example:

  • If the user rarely runs your app then the system won’t give it background fetch time because it’s clear that the user doesn’t care about the app being up to date.

  • If the user runs the app every morning — imagine a news app — the system attempts to detect that and give it background fetch time beforehand.

This is a complex system and it’s not hard to imagine it having bugs.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"