1

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 Answers 2

0

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.

1
  • Not sure what you mean by #sleep , where how to implement ?
    – John Z
    May 26, 2016 at 14:42
0

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!

5
  • Hey thanks , I will give that a try, :) not to worry if it does not work , No Down vote..
    – John Z
    May 26, 2016 at 15:03
  • Thanks! keep me updated if it worked! I got interested in knowing May 26, 2016 at 15:23
  • Bashir, nah did not work ... :( oh well thanks for trying.
    – John Z
    May 26, 2016 at 15:25
  • are you sure you can change the brightness in the background?Maybe this is the issue, if the app is in the background it cant control the brightness anymore May 26, 2016 at 15:29
  • I think you may be correct , I have tried a few different ways , I am logging when app enters background but it appears the code is not executed.
    – John Z
    May 26, 2016 at 15:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.