Wondering if someone could help me with this, or at least point me in the right direction.
I've been searching for documentation on how to get/set settings in a React Native iOS app so that those settings appear in the iOS Settings app listed under my app. I see that there is a Settings API, but it appears that the documentation is not complete. The function definitions are listed there, but that's it. No examples or anything.
Can anyone provide me with a simple example, or point me to a tutorial or something that will help me get going? I'm assuming I import Settings from react-native, just like I would do for other APIs, but beyond that I'm not sure where to go.
Thanks.
React Native enables you to write Android and iOS apps using JavaScript. It uses React's virtual DOM concept to manipulate native platform UI components, providing a familiar experience to users. There are two ways to build iOS apps: React Native CLI: More complex but gives you more control over your app.
then you can check for the permission and if not provided/restricted, you can direct user to settings app to enable the same. Opening a settings app in React Native is so simple, we can open it directly in React Native using Linking. Linking API provides an openSettings () function which will redirect to Settings App.
npx react-native run-ios is one way to run your app. You can also run it directly from within Xcode. If you can't get this to work, see the Troubleshooting page. The above command will automatically run your app on the iOS Simulator by default. If you want to run the app on an actual physical iOS device, please follow the instructions here.
If you want to be able to switch between different Node versions, you might want to install Node via nvm-windows, a Node version manager for Windows. React Native also requires Java SE Development Kit (JDK), which can be installed using Chocolatey as well. If you have already installed Node on your system, make sure it is Node 12 or newer.
The Expo client app usually gains support for a given React Native version about a week after the React Native version is released as stable. You can check this document to find out what versions are supported.
As stated in React Native documentation :
Settings
serves as a wrapper forNSUserDefaults
, a persistent key-value store available only on iOS.
If you want to add iOS Settings bundle to your app you can use this.
As per Chris Sheffield's comment, here is what I have succeeded with so far:
File
> New
> File
Next
Settings.bundle
Root.plist
file inside of the bundle
item
's Identifier
Settings.get('<identifier>')
like either of these:
const varName = Settings.get('var_name')
const [ varName ] = useState(Settings.get('var_name'));
I suggest using some method of watching for changes so that your app updates when the user changes settings while it's running, but these are the only parts required.
I also do not suggest since that t letting the user change those specific settings in-app since that goes against the principle of Single Source of Truth, but it's your app, you do what's best for you and your users.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With