Search code examples
reactjsnativeandroid-permissions

How to ask location permission in react native.60?


I also added Fine.Location permission to line in minifest.Xml file but nothing happen. My targetsdkverion =28. Please suggest me a solution


Solution

  • you should use react-native-geolocation-service and get permissions according to platform. On android you need to request permission on your own like bellow:

    if (Platform.OS !=='android' )   
        Geolocation.requestAuthorization()
    else {
        try {
            const granted = await PermissionsAndroid.request(
                PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,
                {
                    title: 'we need GPS location service',
                    message:
                    'we need location service to provide your location',
                    // buttonNeutral: 'Ask Me Later',
                    buttonNegative: 'Cancel',
                    buttonPositive: 'OK',
                },
            )
            if (granted === PermissionsAndroid.RESULTS.GRANTED) {
            } else {
                Defaults.modal.current.renderModel(modalOptions);
                return false;
            }
        } 
        catch (err) {
            console.warn(err);
        }
    }