Vin*_*rma 5 settings android ios react-native
我正在使用React Native开发移动应用程序,当用户单击特定按钮时,我想在其中打开移动设备的设置。
我已经浏览了RN的文档,但仍然找不到任何可以帮助我实现相同目标的内容。有人可以指导我,如何实施?
谢谢 :)
A.K*_*aus 16
作为Rafael Perozin答案的补充。
在Android上,您还可以通过Linking发送Intent。
import { Button, Linking } from "react-native";
const Screen = () => (
<Button
title="Open Settings"
onPress={() => {
Platform.OS === 'ios'
? Linking.openURL('App-Prefs:Bluetooth')
: Linking.sendIntent("android.settings.BLUETOOTH_SETTINGS");
}}
/>
);
Run Code Online (Sandbox Code Playgroud)
就我而言,我想将用户发送到蓝牙设置,但CR7答案对我不起作用。
所以,我使用以下方法解决了这个问题:
Linking来自react-nativeAndroidOpenSettings来自react-native-android-open-settings我还使用了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>
);
...
Run Code Online (Sandbox Code Playgroud)
小智 -4
您是否尝试使用react-native(v0.60+)形式的链接组件?
import { Button, Linking } from "react-native";
const Screen = () => (
<Button
title="Open Settings"
onPress={() => {
Linking.openSettings();
}}
/>
);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1508 次 |
| 最近记录: |