{"id":19626,"date":"2017-11-21T14:44:16","date_gmt":"2017-11-21T19:44:16","guid":{"rendered":"https:\/\/mjtsai.com\/blog\/?p=19626"},"modified":"2018-03-23T11:25:34","modified_gmt":"2018-03-23T15:25:34","slug":"ios-background-transfer","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2017\/11\/21\/ios-background-transfer\/","title":{"rendered":"iOS Background Transfer"},"content":{"rendered":"<p><a href=\"https:\/\/topologyeyewear.github.io\/engineering-blog\/2017\/11\/20\/background_transfer\/\">Agnes Vasarhelyi<\/a> (<a href=\"https:\/\/twitter.com\/vasarhelyia\/status\/932628350186659840\">tweet<\/a>):<\/p>\n<blockquote cite=\"https:\/\/topologyeyewear.github.io\/engineering-blog\/2017\/11\/20\/background_transfer\/\">\n<p>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.<\/p>\n<p>[&#8230;]<\/p>\n<p>To find out when your tasks did complete when your app was terminated while doing background transfer, you can implement that <a href=\"https:\/\/developer.apple.com\/documentation\/uikit\/uiapplicationdelegate\/1622941-application\" target=\"_blank\" rel=\"external\">one function<\/a> on the <code>AppDelegate<\/code> for handling the results of those sessions. The tricky part here, is that it provides a completion handler that&rsquo;s very important for you to <em>call it as soon as possible<\/em>. Remember, iOS judges you if you spend too much time executing code in the background. This is how it measures it.<\/p>\n<p>[&#8230;]<\/p>\n<p>How does iOS punish you? One way is by not waking you up in the background to receive silent push notifications.<\/p>\n<p>Silent pushes are the only way to wake up your app from your server, indicating there&rsquo;s work to do, such as download data.<\/p><\/blockquote>\n\n<p>Something seems to have changed in iOS 11, as OmniFocus now rarely syncs in the background for me.<\/p>\n\n<blockquote cite=\"https:\/\/topologyeyewear.github.io\/engineering-blog\/2017\/11\/20\/background_transfer\/\"><p>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.<\/p>\n<p>According to Apple, <a href=\"https:\/\/forums.developer.apple.com\/thread\/28713\" target=\"_blank\" rel=\"external\">client authentication doesn&rsquo;t work with background sessions<\/a>. Don&rsquo;t even try.<\/p>\n<p>[&#8230;]<\/p>\n<p>But even after re-engineering for only what works, we learned that iOS will still punish you for some approaches that are fully supported. <em>Any<\/em> server-trust authentication is unwise.<\/p>\n<p>Please make sure to read <a href=\"https:\/\/forums.developer.apple.com\/thread\/28713\" target=\"_blank\" rel=\"external\">Quinn the eskimo&rsquo;s responses to Alexis near the bottom of the dev forum thread<\/a> carefully, if you want to understand why Apple doesn&rsquo;t encourage this kind of authentication method when implementing background sessions.<\/p>\n<\/blockquote>","protected":false},"excerpt":{"rendered":"<p>Agnes Vasarhelyi (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 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"apple_news_api_created_at":"","apple_news_api_id":"","apple_news_api_modified_at":"","apple_news_api_revision":"","apple_news_api_share_url":"","apple_news_coverimage":0,"apple_news_coverimage_caption":"","apple_news_is_hidden":false,"apple_news_is_paid":false,"apple_news_is_preview":false,"apple_news_is_sponsored":false,"apple_news_maturity_rating":"","apple_news_metadata":"\"\"","apple_news_pullquote":"","apple_news_pullquote_position":"","apple_news_slug":"","apple_news_sections":"\"\"","apple_news_suppress_video_url":false,"apple_news_use_image_component":false,"footnotes":""},"categories":[4],"tags":[56,31,1472,26,772,476,526,71,1074,48],"class_list":["post-19626","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-debugging","tag-ios","tag-ios-11","tag-iosapp","tag-ios-multitasking","tag-networking","tag-omnifocus","tag-programming","tag-push-notifications","tag-security"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/19626","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/comments?post=19626"}],"version-history":[{"count":2,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/19626\/revisions"}],"predecessor-version":[{"id":20924,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/19626\/revisions\/20924"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=19626"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=19626"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=19626"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}