Search code examples
iosswiftipadhome-automation

iOS 8 run app forever or disable screen


I'm building a home automation system, I have chosen iPad as the main hub/bridge device to control lots of bluetooth devices (some custom made using RFDuino).

The iPad (iOS 8.4.1) is mounted on the wall and plugged into charger all the time.

I need to choose the right approach to make the app run all the time to control the devices and receive updates, trigger events etc.

The question is: Is there a way to disable the screen visualy? Dimming it down is not good enough; it would be best if the screen were switched off, like in the locked device state.

In simple words, can I employ a black screen saver?

If the answer for above is no: Is there a way to force the app to run in the background forever?

One thing to highlight here. This app does not go to Apple Store so the solution might be a dirty workaround

Thanks in advance

Tested so far:

let backgroundQueue = dispatch_get_global_queue(QOS_CLASS_BACKGROUND,0)

func applicationDidEnterBackground(application: UIApplication) {

    application.beginBackgroundTaskWithName("myBgTask", expirationHandler: nil)
    dispatch_async(self.backgroundQueue, myBackgroundTask)
}

func myBackgroundTask() {
    NSThread.sleepForTimeInterval(1)
    dispatch_async(self.backgroundQueue, myBackgroundTask)
}

This approach keeps app running in the background for 3 minutes only.

Keep searching...


Solution

  • Try the UIApplicationExitsOnSuspend solution:

    Since iOS 4 apps get suspended when you hit the home button. Before this (iOS 3) they would exit and relaunch every time you opened the app - however if you didn't use the home button to close the app but instead locked the device with your iOS 3 app open it would run in the background forever. You can get your apps to work like this by adding the UIApplicationExitsOnSuspend key to your info plist, set the value to YES.

    You wont be able to close and reopen the app as fast (it will relaunch every time you use the home button), but if you don't interact with the iPad very often, then you can just lock the device while the app is open and it will continue to run until the iPad is unlocked or you open another app.

    Note that this solution is valid for the App Store, as it uses official Apple APIs.

    https://developer.apple.com/library/ios/documentation/General/Reference/InfoPlistKeyReference/Articles/iPhoneOSKeys.html