6

How can I enable my app to use iOS 7 background update capability? I notice some apps already do it, but it doesn't seem to be automatic for all.

John Riselvato
  • 12,854
  • 5
  • 62
  • 89
William Falcon
  • 9,813
  • 14
  • 67
  • 110
  • 2
    It's covered in the documentation and some WWDC videos. The details are still covered by the NDA, though, so you're not likely to get a more precise answer here. – Stephen Darlington Sep 11 '13 at 12:30
  • Ok. Where in the documentation can this be found? Most people here probably already have iOS7 as most of us are developers – William Falcon Sep 11 '13 at 12:34
  • Theres a video session on it – heinst Sep 11 '13 at 12:38
  • Did you look in the "What's new in iOS 7" document that's on the front page of the Developer Center? – Stephen Darlington Sep 11 '13 at 12:51
  • iOS 7 supports two new background execution modes for apps. 1.Apps that regularly update their content by contacting a server can register with the system and be launched periodically to retrieve that content in the background. 2.Apps that use push notifications to notify the user that new content is available can fetch the content in the background. In these, how you want to do background updated in ur app? I will let you know on how to do that? – Nandha Sep 17 '13 at 07:10
  • The first way. Contact server – William Falcon Sep 17 '13 at 11:02

1 Answers1

13

According to What's New in iOS 7, what you're looking for is described as:

Apps that regularly update their content by contacting a server can register with the system and be launched periodically to retrieve that content in the background. To register, include the UIBackgroundModes key with the fetch value in your app’s Info.plist file. Then, when your app is launched, call the setMinimumBackgroundFetchInterval: method to determine how often it receives update messages. Finally, you must also implement the application:performFetchWithCompletionHandler: method in your app delegate.

Inside, application:performFetchWithCompletionHandler:, you have a total of 30 seconds to finish executing what you need to do before you have to call the completionHandler. It's definitely advised to execute your poll as quickly as possible and call completionHandler as soon as you're done with your execution. If you don't call it within the allotted 30 seconds, your app will be suspended from background fetching. Or, if you start taking a long time for each fetch, your app will get fewer opportunities to perform background fetches in the future.

Alternatively, if you were looking to execute additional code when a push notification is received:

Apps that use push notifications to notify the user that new content is available can fetch the content in the background. To support this mode, include the UIBackgroundModes key with the remote-notification value in your app’s Info.plist file. You must also implement the application:didReceiveRemoteNotification:fetchCompletionHandler: method in your app delegate.

Mr. T
  • 12,795
  • 5
  • 39
  • 47