简体   繁体   English

反应本机 expo iOS 无法询问物理设备上的后台位置

[英]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:调试问题需要考虑一些因素:

  1. Make sure that location access enables.确保启用位置访问。 await Location.hasServicesEnabledAsync()

  2. 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.

相关问题 IOS上的React Native和Expo位置不要求权限 - React Native and Expo location on IOS not asking for permissions 在物理iOS设备上无法启动react-native(9.3) - Trouble launching react-native on physical iOS device (9.3) React Native iOS调试物理设备WebSocket连接失败 - React Native iOS Debugging Physical Device WebSocket Connection Failure gl-react-native 不在物理 iOS 设备上显示图像 - gl-react-native not displaying image on physical iOS device 在iOS物理设备上反应Native的ScrollView损坏 - React Native's ScrollView Broken on iOS Physical Device FCM - 使用 expo 向 iOS 设备发送通知(反应原生) - FCM - Send a notification to iOS device using expo (React native) 在与博览会的本机反应中请求读取短信的权限 - Ask permission for read SMS in react native with expo 无法编译 React Native iOS 应用以在物理设备上运行,React Native Firebase 出现问题 - Can't compile React Native iOS app to run on physical device, issue with React Native Firebase 如何在Google Chrome上调试在物理iOS设备上运行的React Native应用程序 - How to debug on Google Chrome my React Native application running on physical iOS device Expo / React-Native,有没有办法在设备/模拟器上测试运行独立的iOS应用程序? - Expo / React-Native, Is it there a way to test-run standalone iOS apps on a device/simulator?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM