简体   繁体   English

从 iOS 中的另一个应用程序打开设置应用程序 - React Native

[英]Open Settings App from another App in iOS - React Native

I'm going through the docs in React Native and can only find navigating to external links from the app I am in.我正在浏览 React Native 中的文档,但只能从我所在的应用程序中找到导航到外部链接的内容。

I want to be able to navigate to the Settings app (more specifically to the privacy > location services page) but, can not seem to find the necessary information on it.我希望能够导航到“ Settings应用程序(更具体地说是“隐私”>“位置服务”页面),但似乎无法找到必要的信息。 There is the native iOS way of doing it which I am trying to replicate through React Native.有一种原生的 iOS方式,我试图通过 React Native 进行复制。

Is this possible?这可能吗?

I have tried the following to detect if there is a Settings URL.我尝试了以下方法来检测是否有设置 URL。 The console logs that the Settings url works however, it does not navigate to that page.控制台记录Settings url works ,但它不会导航到该页面。

Update: thanks to @zvona I am now navigating to the settings page but not sure how to get to a specific deep link.更新:感谢@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}`)
})

You can access settings of the application with: Linking.openURL('app-settings:');您可以通过以下方式访问应用Linking.openURL('app-settings:');

But I don't know (yet) how to open a specific deep-link.但我不知道(还)如何打开特定的深层链接。

I successfully opened the settings by the code below, hope it's helpful :)我通过下面的代码成功打开了设置,希望有帮助:)

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));

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

Since React Native version 0.59 this should be possible using openSettings();从 React Native 0.59 版开始,这应该可以使用openSettings(); . . This is described in the React Native Linking documentation .这在 React Native Linking 文档中有所描述。 Although it did not work for me.虽然它对我不起作用。 When I tried quickly I saw a _reactNative.Linking.openSettings is not a function error message.当我快速尝试时,我看到_reactNative.Linking.openSettings is not a function错误消息。

Linking.openSettings();

You can deep-link referencing the settings's index like so:您可以像这样深度链接引用设置的索引:

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

For example Linking.openURL('app-settings:{3}') would open the Bluetooth settings.例如Linking.openURL('app-settings:{3}')将打开蓝牙设置。

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

Adding an answer that worked for me and is easy to apply.添加对我有用且易于应用的答案。

openSettings function in @react-native-community/react-native-permissions works for both iOS and Android. @react-native-community/react-native-permissions 中的openSettings函数适用于 iOS 和 Android。

Calling openSettings function will direct the user to the settings page of your app.调用 openSettings 函数会将用户定向到您应用的设置页面。

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

You can import Linking from 'react-native' and then use Linking.openSettings() to trigger the call.您可以从“react-native”导入链接,然后使用 Linking.openSettings() 触发调用。 This link explains it very concisely:这个链接非常简洁地解释了它:

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

You can use the most easiest way to open the app setting from react-native.您可以使用最简单的方法从 react-native 打开应用设置。 just, import { Linking } from 'react-native';只是,从'react-native'导入{链接}; and user below line anywhere you want open the app setting.和用户在任何你想打开应用程序设置的地方。 Linking.openSettings(); Linking.openSettings();

Old question, but this didn't work for me on Android and I found something that did.老问题,但这对我在 Android 上不起作用,我发现了一些有用的东西。 Hope this helps anyone looking for the same.希望这可以帮助任何寻找相同的人。 :) :)

https://github.com/lunarmayor/react-native-open-settings I don't have the ability to test it for iOS though. https://github.com/lunarmayor/react-native-open-settings虽然我没有能力为 iOS 测试它。

Opens the platform specific settings for the given application.打开给定应用程序的平台特定设置。

For example: to navigate under Settings/Bluetooth you have to use Linking.openURL('App-Prefs:Bluetooth');例如:要在设置/蓝牙下导航,您必须使用Linking.openURL('App-Prefs:Bluetooth');

For iOS 14 and ReactNative 16.13适用于 iOS 14 和 ReactNative 16.13

You can handle your case using Linking from react-native.您可以使用来自 react-native 的 Linking 处理您的案例。 In my case, I accessed the touch id settings on IOS using:-就我而言,我使用以下方法访问了 IOS 上的触摸 ID 设置:-

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM