【发布时间】:2021-09-13 02:33:32
【问题描述】:
我正在开发一个应用程序,有时需要跟踪我的用户,因为他们在应用程序之外。我浏览了世博会文档,看来我应该使用前台和后台权限异步函数,但我的世博会应用程序无法识别任何一个版本。有人遇到过这种情况么?我该如何解决?以下是我的一些代码:
import * as Permissions from 'expo-permissions';
import * as Request from 'expo-permissions';
import * as Location from 'expo-location';
import Constants from 'expo-constants'
useEffect(() => {
(async () => {
if (Platform.OS === 'android' && !Constants.isDevice) {
setErrorMsg(
'Oops, this will not work on Snack in an Android emulator. Try it on your device!'
);
return;
}
let { status } = await Location.requestForegroundPermissionsAsync();
if (status !== 'granted') {
setErrorMsg('Permission to access location was denied');
return;
}
let location = await Location.getCurrentPositionAsync({});
setLocation(location);
})();
}, []);
useEffect (() =>{
(async () => {
if (Platform.OS === 'android' && !Constants.isDevice){
setErrorMsg2(
'Whoops'
);
return;
}
let { status2 } = await Location.requestBackgroundPermissionsAsync();
if (status2 !== 'granted') {
setErrorMsg2('Permission to access background location was denied');
return;
}
let location2 = await Location.getCurrentPositionAsync({})
setLocation2(location2)
})()
},[])
let text = 'Waiting..';
if (errorMsg) {
text = errorMsg;
}
else if (location) {
text = JSON.stringify(location);
}
let text2 = 'Also Wating...';
if (errorMsg2){
text2 = errorMsg2;
}
else if (location) {
text2 = JSON.stringify(location)
}
我在托管工作流中运行 Expo,目前使用 Expo 3.23.2 版本,但也在 4.3.2 版本上对其进行了测试,并且遇到了同样的错误。
【问题讨论】:
标签: javascript react-native permissions background expo