25

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...

Greg Lukosek
  • 1,774
  • 20
  • 40
  • By "disabling the screen", do you want to prevent user from using the iPad at all and not allowing him/her to unlocked the device? – Yuchen Sep 06 '15 at 17:22
  • Nope. All I want is not to look at the ipad hanging on the wall with its screen on but still perform full app functionality in the background. It should work like a typical screen saver. On any input should go back to live, after some time should go back to the black screen state – Greg Lukosek Sep 06 '15 at 17:25
  • It's better option to use Android tablet for that, because it is much more customizable – Andrey Sep 06 '15 at 17:25
  • 5
    Android in my house is not an option. Anyways. the question is regarding iOS – Greg Lukosek Sep 06 '15 at 17:26
  • 2
    Can you use a phone instead of an iPad? If you set the UIApplication `proximityMonitoringEnabled` property to `YES` and cover the proximity sensor (the dot adjacent to the ear speaker that isn’t the camera), it should turn the screen off automatically without sending your application to the background. – Noah Witherspoon Sep 06 '15 at 21:11
  • Has to be iPad. On the other note does your iPhone solution still work on iOS8? – Greg Lukosek Sep 06 '15 at 21:14
  • Shouldn't you be able to use [`UIBackgroundMode: bluetooth-central`](https://developer.apple.com/library/ios/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/BackgroundExecution/BackgroundExecution.html#//apple_ref/doc/uid/TP40007072-CH4-SW23) in your Info.plist? – Siguza Sep 09 '15 at 09:35
  • According to Apple docs it only gives around 10 seconds to process and will shut the app. Might be the solution for simple system, but this need to run the logic all the time – Greg Lukosek Sep 09 '15 at 09:50
  • Why not just disable screen saver/energy saving, and keep your app running in foreground? And if you need an "empty" screen – just make an empty screen in the storyboard. – Denis Mysenko Sep 13 '15 at 04:10
  • This will keep the screen black with the backlight on. Really don't want to see the black box shining on the main wall in the living room. – Greg Lukosek Sep 13 '15 at 06:36

3 Answers3

9

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

SomeGuy
  • 9,670
  • 3
  • 32
  • 35
4

All apps get up to 10 minutes to finish whatever they were doing before the app is truly suspended. But in some cases they may need to run longer such as playing music or calculating steps. It can be done using Required background mode are the modes by which you can keep your application running forever in background.

please look at the below images:

enter image description here enter image description here

Visit for Background Execution: Apple

Visit below URL's it may be helpful.

https://stackoverflow.com/a/29168981/4101371

http://www.raywenderlich.com/29948/backgrounding-for-ios (for explaination with sample code.)

Hope it helps in solving your problem.

Community
  • 1
  • 1
Dhaivat Vyas
  • 2,926
  • 1
  • 16
  • 26
  • Still studying the Ray Wenderlich stuff. Testing all of the approaches. At the moment can only run in the background for no longer than 3 minutes. There are some changes in iOS 8.4.1 to prevent artificially extending the app life – Greg Lukosek Sep 09 '15 at 13:29
  • 1
    @CaptJak - You should first read the documentation provided by the apple. If there will be no processing going on in background application will terminated. – Dhaivat Vyas Sep 10 '15 at 04:29
  • 2
    @GregLukosek if your app plays some audio, then you can keep running in the background forever. For example spotify or a podcast app are able to run indefinitely in the background. The sound you're playing doesn't have to actually be audible through the speakers (just play a silent track on repeat). Doing this will get your app banned from the App Store, but for an in-house app it works perfectly. – Abhi Beckert Sep 15 '15 at 02:02
-3

Could you bypass/hack by running silence in the background. I can't imagine this to be efficient or the best solution but it might be a work around. I know the creators of Workflow have tried to bypass this as well and have also hit the 10min limit. There workaround is to simple send a local notification at the 9 min mark and tell the user to open the app again so that it can continue to run.

Nick Hayward
  • 178
  • 2
  • 12