javascript - React Native 检测飞行模式
<p><p>有没有办法检测 React Native 应用的飞行模式是否打开/关闭。</p>
<p>我找到了 <a href="https://www.npmjs.com/package/react-native-settings" rel="noreferrer noopener nofollow">npm module</a>在 Android 上实现这一点,但在 iOS 上找不到同样的方法。</p>
<p>如果无法通过 React Native 执行此操作,是否有解决方案可以在 Swift 中编写代码(这将获取飞行模式设置)并将其插入 React Native 应用程序?</p>
<p>谢谢</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p><a href="https://github.com/c19354837/react-native-system-setting" rel="noreferrer noopener nofollow">react-native-system-settings</a>是一个可以检测飞行模式条件的库:</p>
<pre><code>SystemSetting.isAirplaneEnabled().then((enable)=>{
const state = enable ? 'On' : 'Off';
console.log('Current airplane is ' + state);
})
SystemSetting.switchAirplane(()=>{
console.log('switch airplane successfully');
})
</code></pre>
<p>但此时</p>
<blockquote>
<p>isAirplaneEnabled() will always return true for iOS if your device has
no SIM card, </p>
</blockquote>
<p> <a href="https://github.com/c19354837/react-native-system-setting/issues/37" rel="noreferrer noopener nofollow">see detail here</a> </p></p>
<p style="font-size: 20px;">关于javascript - React Native 检测飞行模式,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/47713872/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/47713872/
</a>
</p>
页:
[1]