Settings API broken in Expo

The React Native Settings API appears to be broken in Expo.

I tested by creating new a project using react-native init. The Settings API works as expected. But when I create a new project using expo init, I get the following error:

null is not an object (evaluating 'this._settings[key]')
- node_modules/react-native/Libraries/Settings/Settings.ios.js:24:26 in get
* App.js:11:35 in onPress
- node_modules/react-native/Libraries/Components/Touchable/TouchableOpacity.js:235:45 in touchableHandlePress
- node_modules/react-native/Libraries/Components/Touchable/Touchable.js:878:34 in _performSideEffectsForTransition
- ... 21 more stack frames from framework internals

Here is the test code:

import React from 'react';
import { Button, SafeAreaView, Settings } from 'react-native';

export default function App() {
  return (
    <SafeAreaView>
      <Button
        title="Test Settings"
        onPress={() => {
          try {
            const v = Settings.get('mykey');
            alert(v);
          } catch (e) {
            console.log(e);
            alert(e);
          }
        }}
      />
    </SafeAreaView>
  );
}

It appears that NativeSettingsManager is null here https://github.com/facebook/react-native/blob/master/Libraries/Settings/Settings.ios.js#L21

I wonder if something just needs to be linked in expo?

Others have experienced this as well:

Found a Github issue explaining the situation:

Currently we don’t support Settings feature due to safety reasons.
There is no possibility to access NSUserDefault as long as your app is not detached. If you detach your app you will be able to modify a Podfile. As a result, you will be able to use Settings feature.

Glad you found the answer and thanks for sharing it with the rest of the community.

Cheers,
Adam

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.