react-native-android-location-enabler: Error: Undefined an object reactNativeAndroidLocationEnabler2

I run this package with genymotion – android 6.0 and have this error Please give me any help. Thanks! package.js:

"react": "16.5.0",
"expo": "^31.0.2",
screen shot 2018-12-01 at 9 26 48 pm

About this issue

  • Original URL
  • State: open
  • Created 6 years ago
  • Reactions: 3
  • Comments: 19 (5 by maintainers)

Most upvoted comments

Here is my code.

import React from 'react';
import { AppRegistry, Text, View, TouchableOpacity, StyleSheet, Alert } from 'react-native';
import RNAndroidLocationEnabler from 'react-native-android-location-enabler';
export default class App extends React.Component {
  constructor(props) {
      super(props);
    }

    componentDidMount() {
      RNAndroidLocationEnabler.promptForEnableLocationIfNeeded({interval: 10000, fastInterval: 5000})
        .then(data => {
          console.log("Location turn on")
        }).catch(err => {
          console.log("Location error: ", err)
        });
    }

    render() {
      return (
        <View style={style.container}>
          <Text style={style.text}>Hello</Text>
        </View>
      );
    }
  }

  const style = StyleSheet.create({
    container: {
      flex: 1,
      alignItems: 'center',
      justifyContent: 'center',
    },
    button: {
      padding: 20,
    },
    text: {
      fontSize: 20,
    },
    textSuccess: {
      fontSize: 20,
      color: 'green',
    },
  });

the image above was checkout. I created new project and have the same error image

when I import the module import RNAndroidLocationEnabler from 'react-native-android-location-enabler'; I get in RNAndroidLocationEnabler undefined value

@andrey-shostik Are you running this on iOS, as far as I’m concerned this will be null or undefined for iOS, wrap this function inside a platform check. I have realised this only works with Android since it’s there’s a different procedure for toggling location on and off for iOS. Do something like:

if (Platform.OS === 'android') {
  toggleLocation(); // check whether location is enabled or not
} else {
  // block to check ios location enabled or not
}

Ok, I’ll will check this asap.