iOS 8 run app forever or disable screen
Asked Answered
R

3

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

Rafe answered 6/9, 2015 at 17:17 Comment(10)
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?Benedick
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 stateRafe
It's better option to use Android tablet for that, because it is much more customizableSegmental
Android in my house is not an option. Anyways. the question is regarding iOSRafe
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.Vikki
Has to be iPad. On the other note does your iPhone solution still work on iOS8?Rafe
Shouldn't you be able to use UIBackgroundMode: bluetooth-central in your Info.plist?Duple
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 timeRafe
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.Paulettepauley
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.Rafe
C
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

Competitor answered 15/9, 2015 at 1:47 Comment(2)
Running test overnight. Looks promising. Fingers crossedRafe
Looks like we have a winner! App just passed 10 min threshold and perfectly working with the screen switched off. Thank You Sir! Thanks You @Damo for the bountyRafe
B
5

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://mcmap.net/q/539919/-running-a-app-forever-in-the-background-in-ios-8

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

Hope it helps in solving your problem.

Belgian answered 9/9, 2015 at 12:53 Comment(3)
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 lifeRafe
@CaptJak - You should first read the documentation provided by the apple. If there will be no processing going on in background application will terminated.Belgian
@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.Autogamy
B
-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.

Binge answered 13/9, 2015 at 22:6 Comment(1)
So that means I would literally have to reactivate the app every 10 minutes, That is not a solution at all.Rafe

© 2022 - 2024 — McMap. All rights reserved.