用户第一次拒绝后,再次请求位置权限

时间:2018-09-01 22:41:05

标签: android ios react-native mobile expo

我正在查看博览会的文档,但似乎他们的示例仅触发一次对话框,要求一次位置许可。 如果用户拒绝,我该怎么办才能再次触发该对话框?在反复尝试启动该对话框时,我在控制台中得到的所有信息都是这样:

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

这是我的代码:

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>
    );
  }
}

1 个答案:

答案 0 :(得分:0)

sdk 29上是否有独立的应用程序?如果是的话,您可能想看看Expo GitHub上的this thread

此版本中有一个错误,这是解决方法:

proguard-rules.pro中添加

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

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

然后,在app/build.gradle

buildTypes {
  // ...

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