[英]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 ? 您在sdk 29上是否有独立的应用程序? if yes, you might want to take a look at this thread on the Expo GitHub.
如果是的话,您可能想看看Expo GitHub上的这个线程 。
There's is a bug in this version, and here's the workaround: 此版本中有一个错误,这是解决方法:
in proguard-rules.pro
add this 在
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 *;
}
Then, in app/build.gradle
然后,在
app/build.gradle
buildTypes {
// ...
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
// ...
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.