42

I'm going through the docs in React Native and can only find navigating to external links from the app I am in.

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 iOS way of doing it which I am trying to replicate through 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.

Update: thanks to @zvona I am now navigating to the settings page but not sure how to get to a specific deep link.

Linking.canOpenURL('app-settings:').then(supported => {
            
    console.log(`Settings url works`)
    Linking.openURL('app-settings:'
}).catch(error => {
    console.log(`An error has occured: ${error}`)
})
Samuli Hakoniemi
  • 18,740
  • 1
  • 61
  • 74
Simon
  • 6,413
  • 6
  • 34
  • 57

11 Answers11

67

You can access settings of the application with: Linking.openURL('app-settings:');

But I don't know (yet) how to open a specific deep-link.

2021 update use:

Linking.openSettings();

otherwise your app will be rejected due use of non-public URL scheme

Community
  • 1
  • 1
Samuli Hakoniemi
  • 18,740
  • 1
  • 61
  • 74
  • This navigated to the location page that I needed (which was right at the location access surprisingly). Perhaps iOS is smart enough to know that I am requesting the location based on other areas of my code. – Simon Aug 22 '16 at 14:57
  • 2
    How did you find out which url the settings page was from? I could not find it in the docs – Simon Aug 22 '16 at 15:07
  • 1
    I'm poor with native code, but I just added `NSLog(UIApplicationOpenSettingsURLString);` (which I saw in the answer you linked) to Appdelegate.m and output was `app-settings:` :) – Samuli Hakoniemi Aug 22 '16 at 16:37
  • 6
    what about for android? – Sibelius Seraphini Dec 01 '16 at 16:57
  • @SibeliusSeraphini https://github.com/lunarmayor/react-native-open-settings – shrutim Jul 10 '17 at 23:24
  • 4
    The API has changed for iOS, it should be like this: `Linking.openURL("App-Prefs:root=WIFI");` For Android, this looks like the most comprehensive package: https://github.com/rmrs/react-native-settings – Julian K Jan 11 '18 at 15:50
  • I wrote a quick snack for this a while ago: https://snack.expo.io/@zvona/open-app-settings. It also relies on 3rd party lib **react-native-settings** on Android side. – Samuli Hakoniemi Dec 18 '18 at 08:58
  • 2
    beware your app could get rejected for using private apis: https://stackoverflow.com/a/50167923/3499115 – JBaczuk Dec 03 '19 at 22:16
  • 1
    I figured out how to open deeper. In my case I needed to open location settings, so I used: Linking.openURL('app-settings:Settings:Privacy') – Calhau Jan 20 '20 at 21:04
14

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

user158
  • 12,852
  • 7
  • 62
  • 94
tokinonagare
  • 526
  • 4
  • 5
12

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.

Linking.openSettings();
matthew
  • 2,156
  • 5
  • 22
  • 38
  • 2
    Looks like the documentation might be out of sync with the code on this one. I see it in the code for 0.60, but not any of the 0.59 releases: https://github.com/facebook/react-native/blob/v0.60.0/Libraries/Linking/Linking.js – AHinson Jul 05 '19 at 20:24
  • Note that this works only for apps using native code, not those using expo-cli. See warning at the top of https://reactnative.dev/docs/linking.html – jtschoonhoven Apr 21 '20 at 23:18
7

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.

5

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

风中学者
  • 51
  • 1
  • 1
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.

Calling openSettings function will direct the user to the settings page of your app.

import { openSettings } from 'react-native-permissions';
openSettings();
timothyjoseph
  • 91
  • 2
  • 9
1

You can import Linking from 'react-native' and then use Linking.openSettings() to trigger the call. This link explains it very concisely:

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

Oyebola
  • 141
  • 4
1

For example: to navigate under Settings/Bluetooth you have to use Linking.openURL('App-Prefs:Bluetooth');

For iOS 14 and ReactNative 16.13

Peter Jensen
  • 169
  • 2
  • 5
1

You can use the most easiest way to open the app setting from react-native. just, import { Linking } from 'react-native'; and user below line anywhere you want open the app setting. Linking.openSettings();

0

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. :)

https://github.com/lunarmayor/react-native-open-settings I don't have the ability to test it for iOS though.

Opens the platform specific settings for the given application.

H. Solum
  • 1
  • 1
  • 1
  • hey guys is it possible to open the mobile setting page from external web url too tried to search but didnt found anything... – Neerav Shah Mar 20 '20 at 13:03
0

You can handle your case using Linking from react-native. In my case, I accessed the touch id settings on IOS using:-

Linking.openURL('App-Prefs:PASSCODE');
m4n0
  • 29,823
  • 27
  • 76
  • 89