Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS 8 run app forever or disable screen

Tags:

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

like image 347
Greg Lukosek Avatar asked Sep 06 '15 17:09

Greg Lukosek


2 Answers

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

like image 73
SomeGuy Avatar answered Nov 01 '22 18:11

SomeGuy


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.

like image 33
Dhaivat Vyas Avatar answered Nov 01 '22 19:11

Dhaivat Vyas