question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

iOS does not detect when user manually switches to low power mode

See original GitHub issue

I am using v5.6.1 I want to detect if user triggered power save on device. I thought that this would work but this triggers on power cable in. Is there any other way to get lowPowerMode only when suer change this phone settings?

import { NativeEventEmitter, NativeModules } from 'react-native'
const deviceInfoEmitter = new NativeEventEmitter(NativeModules.RNDeviceInfo);
async componentDidMount() {
this.batteryListener = deviceInfoEmitter.addListener('RNDeviceInfo_powerStateDidChange', status => {
      // {batteryState: "charging", batteryLevel: 0.75, lowPowerMode: true}
});

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:7

github_iconTop GitHub Comments

1reaction
mikehardycommented, Jun 2, 2020

Oh! You are right, looks like we might be missing something here

https://github.com/react-native-community/react-native-device-info/blob/2dea0575e892466c3ddc0965fafb2252f2466497/ios/RNDeviceInfo/RNDeviceInfo.m#L78-L89

Specifically something like

https://developer.apple.com/library/archive/documentation/Performance/Conceptual/EnergyGuide-iOS/LowPowerMode.html

    [[NSNotificationCenter defaultCenter] addObserver:self
       selector: @selector(yourMethodName:)
       name: NSProcessInfoPowerStateDidChangeNotification
       object: nil];

I am happy to merge a PR that does this, it should be a quick hack - go after it directly in node_modules to develop + test it by hooking that and emitting a new powerStateDidChange event, when you get it working use https://github.com/ds300/patch-package (fantastic! if you’ve never seen it) so that your fix never stops working for you, and submit the change as a PR, I can do a release quickly just no time for the testing (that’s the part that really takes the time, IMHO)

0reactions
mikehardycommented, Dec 7, 2022

I welcome PRs, and will merge and release reasonable solutions

Read more comments on GitHub >

github_iconTop Results From Across the Web

iOS does not detect when user manually switches to low ...
I am using v5.6.1. I want to detect if user triggered power save on device. I thought that this would work but this...
Read more >
Low power mode not popping up - Apple Support Communities
whene my battery goes to 20%, the low power mode is not showing up like usually others do. I have to do manually...
Read more >
How to force your iPhone to always stay in Low Power Mode
To check, go to iPhone Settings > Battery and enable Low Power Mode (if not already). Now, turn off the switch for Low...
Read more >
How to Automate Low Power Mode When Your iPhone Battery ...
1. Open the Shortcuts app on your iPhone. 2. Select the Automation tab at the bottom of the screen, then tap the +...
Read more >
Low power mode detection in JavaScript for iOS11?
For iOS 16 Safari, "Low Power Mode" (or say power saving mode) can be detected by checking actual interval of setInterval , because ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found