react-native-idle
Prevent screen to sleep in ReactNative app.
Install
npm install react-native-idle --save react-native link react-native-idle
Usage
import RNIdle from 'react-native-idle'
RNIdle.disableIdleTimer() //保持屏幕常亮
RNIdle.enableIdleTimer() //退出屏幕常亮
npm地址:https://www.npmjs.com/package/react-native-idle
闪退解决方式:
RNIdle.m中替换下面的代码:
RCT_EXPORT_METHOD(disableIdleTimer)
{
// DON'T let the device go to sleep during our sync
dispatch_async(dispatch_get_main_queue(), ^{
[[UIApplication sharedApplication] setIdleTimerDisabled:NO];
[[UIApplication sharedApplication] setIdleTimerDisabled:YES];
});
}
RCT_EXPORT_METHOD(enableIdleTimer)
{
// DON'T let the device go to sleep during our sync
dispatch_async(dispatch_get_main_queue(), ^{
[[UIApplication sharedApplication] setIdleTimerDisabled:NO];
});
}