Agontuk / react-native-geolocation-service

React native geolocation service for iOS and android
https://www.npmjs.com/package/react-native-geolocation-service
MIT License
1.61k stars 291 forks source link

Why Location permission popup not showing in iOS 14.1 ? while its working fine for android. #219

Closed Deepak13312 closed 3 years ago

Deepak13312 commented 3 years ago

React Native iOS *As you can see my code that the location popup permission is not showing in iOS, while I am using "react-native-geolocatio-service". I am struggling with, please help me, it would be more appreciable.**

    onPressLocation = () => {
        var that = this;
        async function requestLocationPermission() {
          const options = {
            maxWidth: 500,
            maxHeight: 500,
            storageOptions: {
              skipBackup: true,
            },
          };
          const granted = await PermissionsAndroid.request(
            PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,
            {
              title: 'ThoughtBulb App location Permission',
              message: 'ThoughtBulb App needs access to your location ',
            },
          );
          if (granted === PermissionsAndroid.RESULTS.GRANTED) {
            Geolocation.getCurrentPosition(
              position => {
                const currentLongitude = JSON.stringify(position.coords.longitude);
                const currentLatitude = JSON.stringify(position.coords.latitude);
                that.setState({
                  currentLatitude: currentLatitude,
                  currentLongitude: currentLongitude,
                });
              },
              error => {
                console.log(error);
              },
              {enableHighAccuracy: true, timeout: 15000, maximumAge: 10000},
            );
          } else {
            alert('Location Permission is denied.');
          }
        }
        if (Platform.OS === 'android') {
          requestLocationPermission();
        } else {
*****Here I need to get iOS location permission popup before execute below funtion.

I think this issue raised after updated the Xcode from 10 to 12*** Geolocation.getCurrentPosition( position => { const currentLongitude = JSON.stringify(position.coords.longitude); const currentLatitude = JSON.stringify(position.coords.latitude); that.setState({ currentLatitude: currentLatitude, currentLongitude: currentLongitude, }); }, error => { console.log(error); }, {enableHighAccuracy: true, timeout: 15000, maximumAge: 10000}, ); } };

Agontuk commented 3 years ago

You're not using requestAuthorization method to ask for permission. Check the docs again.

Deepak13312 commented 3 years ago

Its resolved, Thanks.