![](/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.