React Native:如何在 Android 和 iOS 中打开操作系统设置?

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)


Raf*_*zin 7

就我而言,我想将用户发送到蓝牙设置,但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>
);
...
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)

  • 我试过这个。“链接.openSettings();” 进入应用程序设置,但不会进入手机设置。 (4认同)