【问题标题】:Open Settings App from another App in iOS - React Native从 iOS 中的另一个应用程序打开设置应用程序 - React Native
【发布时间】:2016-12-29 03:10:17
【问题描述】:

我正在浏览 React Native 中的 docs,只能从我所在的应用程序中找到导航到外部链接。

我希望能够导航到Settings 应用程序(更具体地说是隐私> 位置服务页面),但似乎无法在其上找到必要的信息。我正在尝试通过 React Native 复制 native iOS 的方法。

这可能吗?

我尝试了以下方法来检测是否有设置 URL。控制台记录了Settings url works,但是它没有导航到该页面。

更新:感谢@zvona,我现在正在导航到设置页面,但不确定如何访问特定的深层链接。

Linking.canOpenURL('app-settings:').then(supported => {
            
    console.log(`Settings url works`)
    Linking.openURL('app-settings:'
}).catch(error => {
    console.log(`An error has occured: ${error}`)
})

【问题讨论】:

    标签: ios react-native


    【解决方案1】:

    您可以通过以下方式访问应用程序的设置: Linking.openURL('app-settings:');

    但我(还)不知道如何打开特定的深层链接。

    2021年更新使用:

    Linking.openSettings();

    否则您的应用将因使用非公开 URL 方案而被拒绝

    【讨论】:

    • 您是如何知道设置页面来自哪个网址的?我在文档中找不到它
    • 我的本地代码很差,但我刚刚将 NSLog(UIApplicationOpenSettingsURLString);(我在您链接的答案中看到)添加到 Appdelegate.m 并且输出为 app-settings: :)
    • 安卓系统呢?
    • iOS 的 API 发生了变化,应该是这样的:Linking.openURL("App-Prefs:root=WIFI"); 对于 Android,这看起来是最全面的包:github.com/rmrs/react-native-settings
    • 当心你的应用可能会因为使用私有 api 而被拒绝:stackoverflow.com/a/50167923/3499115
    【解决方案2】:

    我通过下面的代码成功打开了设置,希望对你有帮助:)

    Linking.canOpenURL('app-settings:').then(supported => {
      if (!supported) {
        console.log('Can\'t handle settings url');
      } else {
        return Linking.openURL('app-settings:');
      }
    }).catch(err => console.error('An error occurred', err));
    

    参考:https://facebook.github.io/react-native//docs/linking.html

    【讨论】:

      【解决方案3】:

      由于 React Native 版本 0.59,这应该可以使用 openSettings();。这在 React Native Linking documentation 中有描述。虽然它对我不起作用。当我快速尝试时,我看到了 _reactNative.Linking.openSettings is not a function 错误消息。

      Linking.openSettings();
      

      【讨论】:

      【解决方案4】:

      您可以像这样对引用设置的索引进行深层链接:

          Linking.openURL('app-settings:{index}')
      

      例如Linking.openURL('app-settings:{3}') 会打开蓝牙设置。

      【讨论】:

      • 不适用于 iOS10.3.3 + React Native 0.44.3,index=3(以及其他索引,如 1、2、3...)将跳转到 Cellular 数据...
      • 对于iOS 14,您可以拨打Linking.openURL('App-Prefs:Bluetooth')打开蓝牙设置
      【解决方案5】:

      Linking.openURL('app-settings:1');

      【讨论】:

        【解决方案6】:

        添加一个对我有用且易于应用的答案。

        @react-native-community/react-native-permissions 中的openSettings 函数适用于 iOS 和 Android。

        调用 openSettings 函数会将用户引导至您应用的设置页面。

        import { openSettings } from 'react-native-permissions';
        openSettings();
        

        【讨论】:

          【解决方案7】:

          您可以从“react-native”导入链接,然后使用 Linking.openSettings() 来触发调用。这个链接解释得很简洁:

          https://til.hashrocket.com/posts/eyegh79kqs-how-to-open-the-settings-app-in-reactnative-060

          【讨论】:

          • 更新,解释更多
          【解决方案8】:

          您可以使用最简单的方法从 react-native 打开应用设置。 只是, 从 'react-native' 导入 { Linking }; 和用户在您想要打开应用程序设置的任何地方。 Linking.openSettings();

          【讨论】:

            【解决方案9】:

            老问题,但这对我在 Android 上不起作用,我发现了一些有用的东西。希望这可以帮助任何寻找相同的人。 :)

            https://github.com/lunarmayor/react-native-open-settings 不过我没有能力在 iOS 上测试它。

            打开给定应用程序的平台特定设置。

            【讨论】:

            • 大家好,是否可以从外部网址打开移动设置页面也尝试搜索但没有找到任何内容...
            【解决方案10】:

            例如:要在设置/蓝牙下导航,您必须使用Linking.openURL('App-Prefs:Bluetooth');

            适用于 iOS 14 和 ReactNative 16.13

            【讨论】:

            • 截至2020年底,React Native 16.13版本不存在
            【解决方案11】:

            您可以使用来自 react-native 的链接来处理您的案例。就我而言,我使用以下方式访问了 IOS 上的 touch id 设置:-

            Linking.openURL('App-Prefs:PASSCODE');
            

            【讨论】:

              猜你喜欢
              • 1970-01-01
              • 2019-05-17
              • 1970-01-01
              • 2011-08-05
              • 1970-01-01
              • 2018-11-04
              • 1970-01-01
              • 2020-09-06
              相关资源
              最近更新 更多