【发布时间】:2021-04-04 17:12:39
【问题描述】:
我正在创建一个需要用户当前位置并且需要实时运行的应用。我正在使用来自世博会的 Location.startLocationUpdatesAsync() 但我收到以下错误。 app.json 已经配置,并且在手机中我接受了位置权限。有人可以告诉我为什么会出现错误?
app.json
"ios": {
"supportsTablet": true,
"bundleIdentifier": "com.ourtor.ourtorapp",
"buildNumber": "0.0.8",
"infoPlist": { "UIBackgroundModes": [ "location", "fetch" ] }
},
"android": {
"adaptiveIcon": {
"foregroundImage": "./assets/adaptive-icon.png",
"backgroundColor": "#FFFFFF"
},
"permissions": [
"ACCESS_COARSE_LOCATION",
"ACCESS_FINE_LOCATION",
"ACCESS_BACKGROUND_LOCATION"
]
},
map.ts
useEffect( () => {
Location.requestPermissionsAsync().then( async (res) => {
if(res.status === "granted") {
console.log('granted')
await Location.startLocationUpdatesAsync('get-location', {
accuracy: Location.Accuracy.Balanced
})
}
});
}, [])
控制台安卓
granted
[Unhandled promise rejection: Error: Not authorized to use background location services.]
控制台 ios
granted
Background Location has not been configured. To enable it, add 'location' to 'UIBackgroundModes' in Info.plist file.
【问题讨论】:
标签: typescript react-native location expo