[英]React Native detect airplane mode
Is there a way to detect whether the airplane mode is turned on/off for React Native apps. 有没有一种方法可以检测是否为React Native应用打开/关闭飞行模式。
I found the npm module to achieve this on Android but can't find a way to do the same on iOS. 我发现npm模块可以在Android上实现此功能,但是找不到在iOS上执行此操作的方法。
If there's no way to do this via React Native is there a solution to write the code in Swift (which will get the Airplane mode settings) and plug it in React Native app? 如果无法通过React Native进行此操作,是否有解决方案可以在Swift中编写代码(它将获得Airplane模式设置)并将其插入React Native应用中?
Thanks 谢谢
The react-native-system-settings is a library that can detect with conditions the airplane mode : react-native-system-settings是一个库,可以根据条件检测飞行模式:
SystemSetting.isAirplaneEnabled().then((enable)=>{
const state = enable ? 'On' : 'Off';
console.log('Current airplane is ' + state);
})
SystemSetting.switchAirplane(()=>{
console.log('switch airplane successfully');
})
But at this moment the 但是此刻
isAirplaneEnabled() will always return true for iOS if your device has no SIM card,
如果您的设备没有SIM卡,则isAirplaneEnabled()对于iOS始终返回true,
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.