请求“始终”定位权限 - IOS EXPO

问题描述 投票:0回答:1

我需要获得“始终”的许可才能在后台跟踪我的位置。对于 Android,它工作正常且良好,但在 IOS 上,它需要“始终”权限才能工作,但对于 IOS,我无法获得该权限。 我正在使用 expo-location,这是我的代码的一部分......

try {
  let { status: foregroundStatus } =
    await Location.requestForegroundPermissionsAsync();
  if (foregroundStatus !== "granted") {
    setErrorMsg("Permission to access location was denied");
    return;
  } else {
    const { status: backgroundStatus } =
      await Location.requestBackgroundPermissionsAsync();

    if (backgroundStatus !== "granted") {
      setErrorMsg("Permission to access location in the background was denied");
      return;
    }
  }

  await Location.startLocationUpdatesAsync(LOCATION_TASK_NAME, {
    accuracy: Location?.Accuracy?.Balanced,
    timeInterval: 5 * 1000,
    showsBackgroundLocationIndicator: true,
    // distanceInterval: 200,
  });
} catch (error: any) {
  setErrorMsg(`Error: ${error.message}`);
}

如何解决这个问题?

现在它给了我这个错误

Error fetching location: [Error: One of the NSLocation*UsageDescription keys must be present in Info.plist to be able to use geolocation.];

我只需要“始终”许可

我试图获得后台地理定位的许可,但我不能。它只是给我错误

reactjs react-native expo geolocation background-process
1个回答
0
投票

按照错误,您应该编辑

Info.plist
并添加
NSLocation*UsageDescription
才能使用位置权限。

示例:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
...
  <!-- 🚨 Add one of there 🚨 -->

  <key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
  <string>YOUR TEXT</string>

  <key>NSLocationTemporaryUsageDescriptionDictionary</key>
  <dict>
    <key>YOUR-PURPOSE-KEY</key>
    <string>YOUR TEXT</string>
  </dict>

  <key>NSLocationWhenInUseUsageDescription</key>
  <string>YOUR TEXT</string>
...
</dict>
</plist>
© www.soinside.com 2019 - 2024. All rights reserved.