1
votes

I am trying to save battery life for the phone from within my app. My app uses AsyncPort connectivity and when the app goes in the background the ports shut down.

I have tried changing settings in my Info.plist for "Required background modes" and made settings which I thought would help 'App plays audio or streams audio/video using AirPlay', but I do not actually use AirPlay. I am using ports to stream data, so when the app goes to the background the ports shut down.

So I thought I would use [[UIScreen mainScreen] setBrightness: yourvalue]; to conserve battery. Oh yeah it works. But once the app is terminated, the screen stays dark even though best effort to reset the brightness back to alpha 1.0 in app delegate applicationWillTerminate, the screen stays dark.

Any thoughts?

2

2 Answers

0
votes

iOS allows the app a little time before exit from main memory. So You can try a #sleep for a fraction of a second after setting the brightness.

0
votes

I have a dirty method But I don't know if it works so why not giving it a try! I know It is not a clean approach but I am stating now so you wont down vote. in the app will enter background, trigger a NStimer that is 2:59 seconds (the app terminates after 3 mins of inactivity).

The action of the NStimer, is to set the brightness to 1.0 as you want.

In the WillEnterForground, invalidate the timer so it becomes useless.

This way only when in the background this timer will trigger. 1 second before the app terminates it restores the brightness, and if the user opens the app the timer invalidates!

I hope it works!

Happy coding!