首页 > 解决方案 > React Native:如何在 Android 和 iOS 中打开操作系统设置?

问题描述

我正在使用React Native开发一个移动应用程序,我想在用户单击特定按钮时打开移动设备的设置。

我浏览了RN的文档,但仍然找不到任何可以帮助我实现相同目标的东西。有人可以指导我,如何实施?

谢谢 :)

标签: androidiosreact-nativesettings

解决方案


就我而言,我想将用户发送到蓝牙设置,而CR7答案对我不起作用。

所以,我使用以下方法解决了这个问题:

我还使用Platformfromreact-native来检查当前设备是否是 IOS。

见代码:

...
import {Linking, Platform} from 'react-native';
import AndroidOpenSettings from 'react-native-android-open-settings';
...

...
const goToSettings = () =>
  Platform.OS === 'ios'
    ? Linking.openURL('App-Prefs:Bluetooth')
    : AndroidOpenSettings.bluetoothSettings();
...

...
return (
<TouchableOpacity onPress={() => goToSettings()}>
  <Text>Go to settings</Text>
</TouchableOpacity>
);
...

推荐阅读