简体   繁体   中英

Ask for location permission again after user says no the first time

I'm looking at the documentation for expo, but it seems their example only triggers a dialog to ask for location permissions once. What can I do to trigger the dialog again if the user says no? All I get is this in the console on repeat attempts to launch the dialog:

Possible Unhandled Promise Rejection (id: 0):
Error: Location permission not granted

Here's my code:

class PermissionsScreen extends React.Component {
  constructor(props) {
    super(props);
  }

    async getLocationAsync() {
        const { Location, Permissions } = Expo;
        const { status } = await Permissions.askAsync(Permissions.LOCATION);
        if (status === 'granted') {
            return Location.getCurrentPositionAsync({enableHighAccuracy: true});
        } else {
            throw new Error('Location permission not granted');
        }
    }

  render() {
    let s = styles;

    return (
      <View style={s.contain}>
        <Text>I'm going to ask for permissions</Text>
        <TouchableOpacity onPress={() => {
            this.getLocationAsync();
        }}>
          <View style={s.button}>
            <Text style={s.buttonText}>Got it</Text>
          </View>
        </TouchableOpacity>
      </View>
    );
  }
}

Do you have a detached app on sdk 29 ? if yes, you might want to take a look at this thread on the Expo GitHub.

There's is a bug in this version, and here's the workaround:

in proguard-rules.pro add this

-keepclassmembers class * {
  @expo.core.interfaces.ExpoProp *;
}
-keepclassmembers class * {
  @expo.core.interfaces.ExpoMethod *;
}

-keepclassmembers class * {
  @**.expo.core.interfaces.ExpoProp *;
}
-keepclassmembers class * {
  @**.expo.core.interfaces.ExpoMethod *;
}

Then, in app/build.gradle

buildTypes {
  // ...

  release {
    minifyEnabled true
    proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    // ...
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM