1

My app has functionality that works while the device is in the background. I've come across a problem where I need to change functionality if the user turns off/on Low Power Mode, but I'm not sure how to do this if the app is in the background. Is there a way to check the state of the Low Power Mode setting every time it is changed while the app is in the background?

This is the code I want to use for checking Low Power Mode:

if NSProcessInfo.processInfo().lowPowerModeEnabled {
    // Low Power functionality
} else {
    // Normal functionality
}
rmaddy
  • 314,917
  • 42
  • 532
  • 579
  • Why do you need to check it every time it might be changed, especially while your app is in the background? 1. The setting rarely changes. 2. Your app won't be doing much in the background. Simply use the code you posted each time your app is given a chance to do some background update. – rmaddy Apr 29 '19 at 16:44
  • I need to check how fast the user is going with their device, and my app works in the background if low power mode is off. A problem is that I don't want some functionality to work while in Low Power Mode is on, but I can't figure out how to check without bringing the phone into the foreground. – Rosalee Hacker Apr 29 '19 at 16:59
  • What code do you have that runs in the background? Why can't that code also perform the check you posted in your question? – rmaddy Apr 29 '19 at 17:00
  • Because the code comes from an SDK I can't directly edit. – Rosalee Hacker Apr 29 '19 at 17:03
  • If it's code you have no control over then what good is check the battery mode? – rmaddy Apr 29 '19 at 17:08
  • Because this SDK is used for other apps, but I have a specific requirement for my app that uses functionality from their SDK and has different requirements for what can happen depending on the power mode of the device. – Rosalee Hacker Apr 29 '19 at 17:15

0 Answers0