[英]React native expo iOS cannot ask for background location on physical device
I am trying to get background permissions using expo Location.我正在尝试使用 expo Location 获取后台权限。 This works on android and on an iOS simulator but not on a physical iOS device.
这适用于 android 和 iOS 模拟器,但不适用于物理 iOS 设备。
const askLoc = async () => {
const requestForeground = await Location.requestForegroundPermissionsAsync();
if (requestForeground.status === 'granted') {
const requestBackground = await Location.requestBackgroundPermissionsAsync();
if (requestBackground.status === 'granted') {
console.log('background location granted');
}
}
};
This is what my app.json
looks like.这就是我的
app.json
样子。
"ios": {
"infoPlist": {
"NSCameraUsageDescription": "This app uses the camera to send pictures or create a new profile photo.",
"NSPhotoLibraryAddUsageDescription": "User can download documents that were previously uploaded by company",
"NSPhotoLibraryUsageDescription": "User can upload Photos/Documents to be seen by his/her company",
"NSLocationAlwaysUsageDescription": "Location is shared with users company while he/she is completing a task/job.",
"NSLocationWhenInUseUsageDescription": "Location is shared with users company while he/she is completing a task/job.",
"NSUserActivityTypes": ["INSendMessageIntent", "INStartCallIntent"],
"UIBackgroundModes": ["location", "fetch"],
"CFBundleAllowMixedLocalizations": true
}
},
There are some factors you need to consider to debug the issue:调试问题需要考虑一些因素:
Make sure that location access enables.确保启用位置访问。
await Location.hasServicesEnabledAsync()
There's a probability that, recently, you deny location permission definitively.最近,您有可能明确拒绝位置许可。
requestForeground.status
will always resolve as denied
requestForeground.status
将始终解析为denied
Detect if requestForeground.canAskAgain
set to true
otherwise user has already denied this permission and you can open device setting and user grant that permission manually.检测
requestForeground.canAskAgain
是否设置为true
,否则用户已经拒绝了此权限,您可以打开设备设置并手动授予用户该权限。
Here permission response type definition这里权限响应类型定义
export interface PermissionResponse {
status: PermissionStatus;
expires: PermissionExpiration;
granted: boolean;
canAskAgain: boolean;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.