eselk
eselk

Reputation: 6884

Creating iPhone app that runs at startup and every X minutes

I have written an Android app and am now porting to iPhone. The Android version uses a broadcast receiver to get notified when the device is rebooted, and at that time it does a background synchronization with my web server. Then it uses alarm manager to schedule another notification in X minutes (where X is set by the user in my app settings), which just does another background sync.

Is this possible on the iPhone, and what APIs should I be looking at? I'm programming with the latest XCode version (4.5 I think) on OSX Mountain Lion, and will be targeting iPhone mostly but also want something that works on iPad. iPhone 4 (iOS 5.0) and above would be fine as most of my customers have newer devices.

If not obvious, I'm very new to XCode, Mac OS, iOS, and Objective-C (still trying to use Alt-TAB to switch windows).

Upvotes: 0

Views: 102

Answers (1)

Tommy
Tommy

Reputation: 100622

This isn't possible on the iPhone — it's incompatible with Apple's multitasking model. If it helps understand motivation, Apple's basic position is that allowing apps unfettered background execution privileges would be a very bad idea from a battery-life point of view since there's no practical way to ensure that such apps are well written.

You'll need to synchronise on launch and use push notifications if you want to make the user aware of something if they're not currently online. There are some special categories of app that can be awoken for strictly limited time periods upon certain events (like a change in location, receiving a VoIP call or playing audio content) but the list is strict and confined. See this document, in particular paying attention to the stuff from 'Implementing Long-Running Background Tasks' onward.

Upvotes: 2

Related Questions