How to Run an iOS Application Every 1 Minute Infinitely

How to run an iOS application every 1 minute infinitely?

As Apple states in their documentation:

In iOS, only specific app types are allowed to run in the background:

  • Apps that play audible content to the user while in the background, such as a music player app
  • Apps that record audio content while in the background
  • Apps that keep users informed of their location at all times, such as a navigation app
  • Apps that support Voice over Internet Protocol (VoIP)
  • Apps that need to download and process new content regularly
  • Apps that receive regular updates from external accessories

Apps that implement these services must declare the services they
support and use system frameworks to implement the relevant aspects of
those services. Declaring the services lets the system know which
services you use, but in some cases it is the system frameworks that
actually prevent your application from being suspended.

You can read all about implementing and declaring those background tasks in the link. However, if yours is another type of App, or you cannot use the system frameworks, there is no way for your App to run in the background indefinitely. And even if it is, you should always expect that the system stops your task for some reason (f.e. restarting the phone).

Send data to Apple Watch every minute

It's not impossible but any app that does that will not be allowed on the app store. Apps are only supposed to run in the background for a limited time (3 minutes, as you say.)

If you set up your app as a background audio app and play a "silent sound" then you can run in the background indefinitely, but that is a misuse of the entitlement.

Keeping your iPhone app running in the background would drain the battery quickly. Likewise sending a message to the watch every minute would chew through the watch's battery faster than normal. BLE is burst mode and pretty power-efficient, but the watch likely has to go into high power mode to handle the communications.

How do you schedule a task even when the application isn't active?

Facebook app and other apps that send notifications when they were not launched do this by using the remote notification mechanism.

To use this, you need to setup a server, create push certificates and use a APNS library for your preferred server.

Take a look here for details: http://www.raywenderlich.com/3443/apple-push-notification-services-tutorial-part-12

Continuously run an IOS app in the background even after sleep or reboot

I have been able to keep the app running after sleep without jailbreaking the phone or using private API's. As I suspected it was possible, after all, I've seen other apps do it.

The key to keep the app awake is to play an empty background audio in an infinite loop. Permissions required are VOIP and Audio. Even if the phone is asleep for hours the background loop will keep executing.

The second part of this article describes this approach:
http://hayageek.com/ios-long-running-background-task/

Here is a link to an example iPhone app:
http://hayageek.s3.amazonaws.com/downloads/ios/LongRunningBackgroundTask.zip

Edit: To lower battery usage it is possible to run the audio for brief intervals only in applicationDidEnterBackground, which will reset the value of UIApplication.sharedApplication().backgroundTimeRemaining

iOS Timer loop that executes a certain action every X minutes

As written, this is an infinite loop, creating an NSTimer every loop iteration.

Try it without the while loop. This should cause [self timerHandle] to be invoked on interval x by a single background thread/timer. The Apple guide to NSTimer usage (including as others point out, how to properly stop your timed task) is here.



Related Topics



Leave a reply



Submit