Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable background update on iOS 7 apps

Tags:

ios

ios7

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.

like image 677
William Falcon Avatar asked Sep 11 '13 12:09

William Falcon


People also ask

Can iOS update in background?

Background app refresh is a feature of iOS and Android that allows apps to update their content from the internet, even while you're not using them. In contrast, we say that apps use data in the foreground when you open and use them yourself.

Does iOS allow apps to run in background?

Some apps keep running in the background when you return to the home screen. You can set your mobile phone to refresh apps in the background so that you'll still get notifications even if the app isn't actively in use.


1 Answers

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.

like image 101
Mr. T Avatar answered Sep 21 '22 01:09

Mr. T