android - 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>
);
}
}
解决方案
你在 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'
// ...
}
}
推荐阅读
- flutter - Flutter 将 NestedScrollView 添加到 SliverChildListDelegate 并出现 RenderFlex 错误
- python - 提高数据预处理速度 - Python 中的正则表达式
- css - 光滑的滑块捏缩放移动
- timer - F#我不能从10倒数到0
- ios - 在模拟器中选择/保存文件时出错 - Xcode 11.3.1?
- android - android中每个元素的ConstraintLayout等间距
- python - 如何使用具有多个返回值的贝叶斯优化包?
- r - 预测不适用于 R 中的置信区间
- python - 查看实际 CPU 时钟速度 Python
- angular - 表单控件和表单值中的表单控件名称有区别