android - React Native:如何在 Android 和 iOS 中打开操作系统设置?
问题描述
我正在使用React Native开发一个移动应用程序,我想在用户单击特定按钮时打开移动设备的设置。
我浏览了RN的文档,但仍然找不到任何可以帮助我实现相同目标的东西。有人可以指导我,如何实施?
谢谢 :)
解决方案
就我而言,我想将用户发送到蓝牙设置,而CR7答案对我不起作用。
所以,我使用以下方法解决了这个问题:
- IOS:
Linking
从react-native
- 安卓:
AndroidOpenSettings
从react-native-android-open-settings
我还使用Platform
fromreact-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>
);
...
推荐阅读
- c - 为什么我的基于输入的 if 语句不能在 C 中工作?
- https - 对于嵌入式系统来说,简单的 HTTP GET 会是什么样子?
- linux - SCP 无法识别目标文件路径
- python - 重新加载时是否有更好的方法将表单保存在烧瓶中?
- gradle - 错误信息是什么意思:“密钥环不以密钥标签开头:标签 0xffffffff”?
- mysql - 是否可以在不使用 sql 中的 Pivot 函数的情况下将行转换为列然后根据特定值对金额求和?
- mysql - 编写此 MySQL 查询的更有效方法
- c - 汇编中的有效地址
- fullcalendar - fullcalendar 5 没有 monthNames、monthNamesShort、dayNames 和 dayNamesShort 选项
- python - Pydantic 参数验证与文件上传