【问题标题】:React Native: How to open OS settings in Android and iOS?React Native:如何在 Android 和 iOS 中打开操作系统设置?
【发布时间】:2020-08-12 14:20:13
【问题描述】:

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

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

谢谢:)

【问题讨论】:

    标签: android ios react-native settings


    【解决方案1】:

    作为对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");
        }}
      />
    );
    

    【讨论】:

      【解决方案2】:

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

      所以,我解决了这个问题:

      我还使用react-native 中的Platform 来检查当前设备是否为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>
      );
      ...
      

      【讨论】:

      • 你的 iOS 应用程序在 App Store 中获得批准了吗?
      【解决方案3】:

      您是否尝试过使用 Linking 组件形式 react-native (v0.60+)?

      import { Button, Linking } from "react-native";
      
      const Screen = () => (
        <Button
          title="Open Settings"
          onPress={() => {
            Linking.openSettings();
          }}
        />
      );
      

      【讨论】:

      • 我试过这个。 “链接.openSettings();”进入应用设置,但不会进入手机设置。
      猜你喜欢
      • 2017-05-21
      • 1970-01-01
      • 1970-01-01
      • 2019-05-17
      • 1970-01-01
      • 1970-01-01
      • 2020-04-13
      • 2012-07-15
      • 2014-03-11
      相关资源
      最近更新 更多