![](/img/trans.png)
[英]How to ask permission (RunTime) again if the user deny for the first time
[英]Ask for location permission again after user says no the first time
我正在查看博览会的文档,但似乎他们的示例仅触发一次对话框,要求一次位置许可。 如果用户拒绝,我该怎么做才能再次触发对话框? 我得到的只是在控制台上反复尝试启动对话框的过程:
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上的这个线程 。
此版本中有一个错误,这是解决方法:
在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'
// ...
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.