Is there a way to wire a background task (such as toggling the use of location services) in iOS 7 to run at a specific point of time (e.g. tomorrow morning) without the user opening the app, or without having a constantly running background process?
The only option that I am aware of is to have a push notification sent to the device at the desired time, but does anyone know of any purely on-device alternatives for this?
any purely on-device
- unfortunately till now - 2014 there is no such ways. Background task execution if content avaliable
appeared in iOS 7 is rather a good thing but it is push-based.
So when the app is suspended it cannot do ANYTHING
to rouse itself directly. It cannot previously have scheduled an NSTimer
, it cannot make use of something like performSelector:afterDelay
and so on and so forth. The ONLY
way the app can become active again is if the USER HIMSELF
does something to make it active e.g local notification received and an alert poped up. Execution of an app in background mode for a long time is only allowed when an app has a background mode, theses modes are: voip, audio, location, newstand. Note: Starting in iOS 9, kCFStreamNetworkServiceTypeVoIP
is deprecated now, and VoIP apps should use PushKit instead (VoIP high-prioirity push notifications). Even if it has one of these types an application cannot execute its code without some restrictions. You can read about it in the docs. So we have to accept this status of affairs. May be some time in a future Apple engineers will make a true multitasking or at least something like background task execution on local notification received or some global background tasks sheduler for all the apps installed. But I don't believe in this, because limited background execution of 3-rd party processes is a core design of iOS scheduler, which is a modified version of CMU Mach 3 scheduler.