欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

rn保持屏幕常亮 react-native-idle 及1.1.0在iOS模拟器或SE真机闪退的某个原因解决方法

程序员文章站 2022-06-23 08:30:02
react-native-idlePrevent screen to sleep in ReactNative app.Installnpm install react-native-idle --savereact-native link react-native-idleUsageimport RNIdle from 'react-native-idle'RNIdle.disableIdleTimer()//保持屏幕常亮RNIdle.enableIdleTi......

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];

    });

}

本文地址:https://blog.csdn.net/loveseal518/article/details/109644407