Mohammed Tawfik
Mohammed Tawfik

Reputation: 601

IOS schedule action in fixed interval

I am developing an app that I want it to schedule an action to be done in fixed interval say 5 mins even if the app is closed.

Upvotes: 1

Views: 558

Answers (2)

Scrungepipes
Scrungepipes

Reputation: 37581

There is no way for your app to schedule itself to run if its closed (i.e. terminated)

If its in the background it still cannot schedule itself to run on a fixed interval, but it can run at in response to certain external events and at the discretion of the OS.

You could post multiple local notifications before the app closes and then if the user clicks on one then your app would run. But posting a notification to the user every 5 minutes would be an absolutely appallingly bad thing to do and would probably result in the app being rejected from the app store.

There are certain options such as local notifications and push notifications and background fetch if you have a low frequency, which is not regular but irregular. But 5 minutes is short a time period so its totally out of the question to have any solution at all.

In summary there is: a) Absolutely no way of scheduling something in the background in a regular manner (all the alternative are irregular: local push depends on user input, remote push depends on delivery time of the notification; background fetch depends upon when the OS decides it will execute your app, etc. etc. b) Scheduling something irregularly on a frequent basis is simply not possible

Upvotes: 2

user505593
user505593

Reputation: 159

First, when the app is running in foreground you can use NSTimer to perform set of actions after specific time interval. Second, when the app is running in background you cannot do all kind of operations however you can do following things,

  1. Play Audio
  2. VOIP services
  3. Fetch content from the network on a regular basis.
  4. Use remote notifications as a signal to download new content available from network.

Last two background mode can launch or resume your app in background and perform required action. But any operation other than what is intended by each background mode will lead to app store rejection. So, if you operation fits in any of these you are good to go,

For more information you can look at this link under Background modes https://developer.apple.com/library/ios/documentation/general/Reference/InfoPlistKeyReference/Articles/iPhoneOSKeys.html

Upvotes: 2

Related Questions