Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing NSUserDefaults from a React Native application on iOS

I have a React Native app, that is using ExpoKit. I can eject if needed.

I want to access the NSUserDefaults object to read a value that has been pushed by AirWatch - a Mobile Device Management system. Basically the app is run in a Managed Environment, and the settings are passed through NSUserDefaults.

I haven't been able to use React Native's Settings (https://facebook.github.io/react-native/docs/settings), as it gives me an error about the internal _settings object being undefined when trying to access this._settings[t].

How to use this Settings module, or what should I do to access this settings object?

like image 719
Mickaël Avatar asked Dec 29 '25 11:12

Mickaël


1 Answers

Check your pods, you are most probably missing the subspec "RCTSettings" for pod 'React', it was not added during the eject .. which is really strange.

This is how it looks for me:

  pod 'React',
:path => "../node_modules/react-native",
:inhibit_warnings => true,
:subspecs => [
  "Core",
  "ART",
  "RCTActionSheet",
  "RCTAnimation",
  "RCTCameraRoll",
  "RCTGeolocation",
  "RCTImage",
  "RCTNetwork",
  "RCTText",
  "RCTVibration",
  "RCTWebSocket",
  "RCTSettings",
  "DevSupport",
  "CxxBridge"
]
like image 144
EmilDo Avatar answered Dec 31 '25 00:12

EmilDo