1

I need my app to alert the users about certain updates. I am aware that I can do remote notification service but all I want to get, is a small count variable and I was wondering if I could do it with something simple like, pinging the server every 30 minutes, even if the app is not running. I believe that such a provision exists for Android

Sidharth J Dev
  • 927
  • 1
  • 6
  • 25
  • In iOS it's not possible to call service after a given time period while app is in background or not running. If you are using any background service (e.g. location, voip etc) then you can run app in background. – Gagan_iOS Nov 13 '15 at 05:30
  • Basically, its a no? if the user quits the app, then I can't make the app do anything else? APNS is the only option? – Sidharth J Dev Nov 13 '15 at 05:33
  • Apple allows to run any app in background mode for only 10 minutes. After that app will get terminated by OS. If you are trying to download from server then you can use NSURLSession but it is not applicable in your case. You can follow below link for running app in background but I have not tested it in iOS 8 & iOS 9. http://stackoverflow.com/questions/5323634/ios-application-executing-tasks-in-background/11809211#11809211 – Gagan_iOS Nov 13 '15 at 05:35

1 Answers1

2

I think the iOS background mode "background fetch" is exactly what you describe.

From the App Programming Guide for iOS - Background Execution:

Fetching Small Amounts of Content Opportunistically

Apps that need to check for new content periodically can ask the system to wake them up so that they can initiate a fetch operation for that content. To support this mode, enable the Background fetch option from the Background modes section of the Capabilities tab in your Xcode project. (You can also enable this support by including the UIBackgroundModes key with the fetch value in your app’s Info.plist file.) Enabling this mode is not a guarantee that the system will give your app any time to perform background fetches. The system must balance your app’s need to fetch content with the needs of other apps and the system itself. After assessing that information, the system gives time to apps when there are good opportunities to do so.

When a good opportunity arises, the system wakes or launches your app into the background and calls the app delegate’s application:performFetchWithCompletionHandler: method. Use that method to check for new content and initiate a download operation if content is available. As soon as you finish downloading the new content, you must execute the provided completion handler block, passing a result that indicates whether content was available. Executing this block tells the system that it can move your app back to the suspended state and evaluate its power usage. Apps that download small amounts of content quickly, and accurately reflect when they had content available to download, are more likely to receive execution time in the future than apps that take a long time to download their content or that claim content was available but then do not download anything.

When downloading any content, it is recommended that you use the NSURLSession class to initiate and manage your downloads. For information about how to use this class to manage upload and download tasks, see URL Session Programming Guide.

Baris Akar
  • 4,895
  • 1
  • 26
  • 54