【问题标题】:react native expo app ACCESS_BACKGROUND_LOCATION needs to be added to the manifest Problemreact native expo app ACCESS_BACKGROUND_LOCATION 需要添加到 manifest 问题
【发布时间】:2021-12-15 13:51:58
【问题描述】:

我正在使用托管流程构建一个 expo 应用程序(因此我无法直接访问 android 中的清单),我确实阅读甚至记住了文档,它说我需要添加权限我的 app.config.json 文件中的 android.permissions 我做了如下:

"android": {
  "permissions": [
    "ACCESS_BACKGROUND_LOCATION",
    "ACCESS_COARSE_LOCATION",
    "ACCESS_FINE_LOCATION"
  ]
},

它仍然告诉我同样的事情,即使根据文档,这是我唯一需要做的事情来包含许可。但由于某种原因,要么android设备忽略了这一点,要么expo没有将它添加到他们在后台构建的清单中,或者无论出于何种原因,应用程序的行为就像我没有将这些行添加到配置文件中一样。

我尝试过的事情:

  • 我尝试了多种方法,包括删除精细位置权限(因为在某处有人说新的 android 更新只接受一个位置权限;精细位置或背景位置)。这当然没有用。

  • 构建我的应用程序的独立版本(因为有人说 Expo go 不允许在 android 上进行后台定位)

  • 我在 github 和 expo 论坛上看到了多个关于这个问题的问题,最明显的是:

1- issue raised on github
2-issue raised on expo forums

我当然也读过以下内容

expo permissions docs
android config docs on expo

我用来请求权限的代码:

    try {
// at the following line it just breaks and jumps to the catch block
      const { status } = await Location.requestBackgroundPermissionsAsync();
      console.log(
        "@@@@@@@@@@@@@@@@@@@@@@ requestBackgroundPermissionsAsync @@@@@@@@@@@@@@@@@@@@@@"
      );
      console.log(status);
      console.log(
        "@@@@@@@@@@@@@@@@@@@@@@ requestBackgroundPermissionsAsync @@@@@@@@@@@@@@@@@@@@@@"
      );
      if (status === "granted") // ... the rest of the code

    } catch (error) {
      console.log(error);
    }

代码只是在这一行出现错误并告诉我以下内容:

    You need to add `ACCESS_BACKGROUND_LOCATION` to the AndroidManifest.
at node_modules/react-native/Libraries/BatchedBridge/NativeModules.js:103:50 in promiseMethodWrapper
at node_modules/@unimodules/react-native-adapter/build/NativeModulesProxy.native.js:15:23 in moduleName.methodInfo.name
at node_modules/expo-location/build/Location.js:142:7 in requestBackgroundPermissionsAsync
at node_modules/expo-location/build/Location.js:142:22 in requestBackgroundPermissionsAsync
at screens/home/GoToLocation.tsx:156:25 in onGoToLocation
at http://192.168.8.102:19000/node_modules/expo/AppEntry.bundle?platform=android&dev=true&hot=false&minify=false:191029:39 in onGoToLocation
at node_modules/react-native/Libraries/Pressability/Pressability.js:691:17 in _performTransitionSideEffects
at node_modules/react-native/Libraries/Pressability/Pressability.js:628:6 in _receiveSignal
at node_modules/react-native/Libraries/Pressability/Pressability.js:524:8 in responderEventHandlers.onResponderRelease

问题是:这是否像世博会中的一个错误,他们需要修复它还是我做错了什么?如果我做错了什么。请帮忙。

【问题讨论】:

    标签: javascript android react-native expo location


    【解决方案1】:

    经过几天的努力,结果证明是新版本的 expo go app 2.22.3 中的一个错误,它根本没有读取或注册这种类型的权限。所以我刚刚降级到 2.21.5 版本,它工作得很好。

    expo 的一位维护者在 github 上打开的问题上证实了这一点

    github issue and confirmation

    无论如何,他们似乎正在努力,但在修复之前,如果您正在使用 android 进行测试,请使用旧版本的应用程序。

    【讨论】:

      猜你喜欢
      • 2020-02-23
      • 2022-11-16
      • 2021-11-20
      • 1970-01-01
      • 1970-01-01
      • 2019-02-28
      • 2021-03-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多