OGeek|极客世界-中国程序员成长平台

标题: javascript - React Native 检测飞行模式 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 19:24
标题: javascript - React Native 检测飞行模式

有没有办法检测 React Native 应用的飞行模式是否打开/关闭。

我找到了 npm module在 Android 上实现这一点,但在 iOS 上找不到同样的方法。

如果无法通过 React Native 执行此操作,是否有解决方案可以在 Swift 中编写代码(这将获取飞行模式设置)并将其插入 React Native 应用程序?

谢谢



Best Answer-推荐答案


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');
})

但此时

isAirplaneEnabled() will always return true for iOS if your device has no SIM card,

see detail here

关于javascript - React Native 检测飞行模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47713872/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4