Tuesday, November 21, 2017 [Tweets] [Favorites]

iOS Background Transfer

Agnes Vasarh (tweet):

Memory consumption is not the only factor when iOS is judging your app. What also counts is the time your app spends executing in the background and the number of times it wants to be woken up. Keep these in mind when implementing background transfer, because you will want to be a good citizen. iOS ranking your app down means delays in your background execution window, and as mentioned, sometimes might lead to termination.

[…]

To find out when your tasks did complete when your app was terminated while doing background transfer, you can implement that one function on the AppDelegate for handling the results of those sessions. The tricky part here, is that it provides a completion handler that’s very important for you to call it as soon as possible. Remember, iOS judges you if you spend too much time executing code in the background. This is how it measures it.

[…]

How does iOS punish you? One way is by not waking you up in the background to receive silent push notifications.

Silent pushes are the only way to wake up your app from your server, indicating there’s work to do, such as download data.

Something seems to have changed in iOS 11, as OmniFocus now rarely syncs in the background for me.

The biggest surprise of this journey was when authentication between our app and our server broke the minute we switched to background sessions. It stopped working in both the foreground and the background.

According to Apple, client authentication doesn’t work with background sessions. Don’t even try.

[…]

But even after re-engineering for only what works, we learned that iOS will still punish you for some approaches that are fully supported. Any server-trust authentication is unwise.

Please make sure to read Quinn the eskimo’s responses to Alexis near the bottom of the dev forum thread carefully, if you want to understand why Apple doesn’t encourage this kind of authentication method when implementing background sessions.

3 Comments

Yes, OmniFocus rarely automatically syncs for me (although I think that was the case with iOS 10) unless I open the app. In case I needed to do something (use OmniFocus' option to "Regenerate Group" which the apps says you should only need to do if their support people tell you to), I emailed OmniGroup support and got this response:

"I’m really sorry for the trouble this is causing! What we discovered partway through the iOS 10 era was that there are situations where the push message will be delivered to your device… but iOS declines to wake OmniFocus up and allow it to sync. Our system actually delivers the message that’s meant to trigger a sync to your phone, in other words, but iOS doesn’t allow OmniFocus to actually do so.

This is presumably driven by a to ensure that developers that wanted to make their apps look good didn’t run your devices’ batteries down by syncing too frequently. They’ve talked about that concern in talks over the years, at least. This isn't something we can code around on the device, but we’re still going to see if we can find a way of restoring the sort of sync responsiveness you’re accustomed to - while also respecting Apple’s goals in introducing that throttling behavior."

That may be but somehow Overcast seems to get the pushes that cause the podcasts downloads to work. So I don't know if it's because they're using different APIs or if Marco has figured out a way around this. I didn't follow-up with OmniGroup. Note, I'm not blaming OmniGroup - as a developer, I know how frustrating and challenging it is to work with opaque systems.

@Dave Although I think you’re right that it wasn’t perfect before, I personally saw very high reliability ever since they added support for push notifications—until iOS 11, where it almost never works if OmniFocus is in the background. I contacted Omni support, and they seemed to agree that something had changed in iOS 11.

@Michael, you may have gotten a different support person as I also submitted that request in October (after iOS 11 came out) and got that response. I think you're correct that it did work more reliably in iOS 10 but now if I don't open OmniFocus on my iPad (I mainly use OmniFocus on my iPhone and Mac), then the iPad won't sync for days.

Stay up-to-date by subscribing to the Comments RSS Feed for this post.

Leave a Comment