我正在查看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>
);
}
}
你在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'
// ...
}
}