Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Native: How to open OS settings in Android and iOS?

I am developing a mobile application using React Native in which I want to open mobile device's settings when user clicks on a specific button.

I have gone through the docs of RN, but still couldn’t find anything that can help me in achieving the same. Can someone guide me on the same, how can that be implemented?

Thanks :)

like image 918
Vinay Sharma Avatar asked Apr 28 '20 17:04

Vinay Sharma


People also ask

Is React Native compatible with iOS and Android?

React Native combines the best parts of native development with React, a best-in-class JavaScript library for building user interfaces. Use a little—or a lot. You can use React Native today in your existing Android and iOS projects or you can create a whole new app from scratch.


1 Answers

In my case I would like to send the user to Bluetooth settings and the CR7 answer didn't work for me.

So, I solved the problem using:

  • IOS: Linking from react-native
  • ANDROID: AndroidOpenSettings from react-native-android-open-settings

And I also used the Platform from react-native to check if the current device is an IOS.

See the code:

...
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>
);
...
like image 133
Rafael Perozin Avatar answered Oct 17 '22 01:10

Rafael Perozin