【发布时间】:2018-09-01 22:41:05
【问题描述】:
我正在查看世博会的文档,但他们的示例似乎只触发了一个对话框来请求位置权限一次。 如果用户说不,我该怎么做才能再次触发对话框?我得到的只是控制台中重复尝试启动对话框时的这个:
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>
);
}
}
【问题讨论】:
-
尝试从
IntentLauncher启用它 -
@PritishVaidya 我试过
IntentLauncherAndroid.startActivityAsync( IntentLauncherAndroid.ACTION_LOCATION_SOURCE_SETTINGS );但这没有用。
标签: android ios react-native mobile expo