从 iOS 中的另一个应用程序打开设置应用程序 - React Native
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/39081688/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Open Settings App from another App in iOS - React Native
提问by Simon
I'm going through the docsin 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. There is the native iOSway of doing it which I am trying to replicate through React Native.
我希望能够导航到该Settings
应用程序(更具体地说是隐私 > 位置服务页面),但是,似乎无法找到有关它的必要信息。有一种原生的 iOS方式,我试图通过 React Native 进行复制。
Is this possible?
这可能吗?
I have tried the following to detect if there is a Settings URL. The console logs that the Settings url works
however, it does not navigate to that page.
我尝试了以下方法来检测是否有设置 URL。控制台记录了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}`)
})
回答by Samuli Hakoniemi
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.
但我不知道(还)如何打开特定的深层链接。
回答by tokinonagare
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
回答by Alexandra Persea
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}')
会打开蓝牙设置。
回答by matthew
Since React Native version 0.59 this should be possible using openSettings();
. This is described in the React Native Linking documentation. Although it did not work for me. When I tried quickly I saw a _reactNative.Linking.openSettings is not a function
error message.
从 React Native 0.59 版开始,这应该可以使用openSettings();
. 这在 React Native Linking 文档中有所描述。虽然它对我不起作用。当我快速尝试时,我看到了一条_reactNative.Linking.openSettings is not a function
错误消息。
Linking.openSettings();
回答by u7156128
Linking.openURL('app-settings:1');
Linking.openURL('app-settings:1');
回答by timothyjoseph
Adding an answer that worked for me and is easy to apply.
添加对我有用且易于应用的答案。
openSettingsfunction 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();
回答by H. Solum
Old question, but this didn't work for me on Android and I found something that did. Hope this helps anyone looking for the same. :)
老问题,但这对我在 Android 上不起作用,我发现了一些有用的东西。希望这可以帮助任何寻找相同的人。:)
https://github.com/lunarmayor/react-native-open-settingsI 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.
打开给定应用程序的平台特定设置。