You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React Native添加NSLocationAlwaysAndWhenInUseUsageDescription仍遇定位权限错误

React Native iOS地理定位权限问题:已添加Info.plist键仍报错

问题详情

在React Native项目中处理地理定位功能时,已在Info.plist文件中添加NSLocationAlwaysAndWhenInUseUsageDescription键,但仍收到错误提示:

Cannot check or request permission without the required "NSLocationAlwaysAndWhenInUseUsageDescription" entry in your app "Info.plist" file

错误堆栈信息:

-[RNPermissionsModule checkUsageDescriptionKeys:]
    RNPermissionsModule.mm:218
-[RNPermissionsModule handlerForPermission:]
-[RNPermissionsModule request:resolve:reject:]
__invoking___
-[NSInvocation invoke]
-[NSInvocation invokeWithTarget:]
-[RCTModuleMethod invokeWithBridge:module:arguments:]
facebook::react::invokeInner(RCTBridge*, RCTModuleData*, unsigned int, folly::dynamic const&, int, (anonymous namespace)::SchedulingContext)
facebook::react::RCTNativeModule::invoke(unsigned int, folly::dynamic&&, int)::$_0::operator()() const
invocation function for block in facebook::react::RCTNativeModule::invoke(unsigned int, folly::dynamic&&, int)
_dispatch_call_block_and_release
_dispatch_client_callout
_dispatch_main_queue_drain
_dispatch_main_queue_callback_4CF
__CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__
__CFRunLoopRun
CFRunLoopRunSpecific
GSEventRunModal
-[UIApplication _run]
UIApplicationMain
main
start_sim
0x0

已尝试以下两种解决方案但均无效:

  • iOS 11和iOS 10定位权限相关修复方案
  • react-native-maps仓库对应issue的修复方案

可行排查与解决步骤

  1. 确认Info.plist修改有效性

    • 检查修改的是否为项目根目录下ios/[项目名称]/Info.plist文件,而非其他副本
    • 清理Xcode缓存:按下Cmd+Shift+K清理构建文件夹,重启Xcode后重新编译
    • 核对键名拼写与大小写,确保完全匹配NSLocationAlwaysAndWhenInUseUsageDescription,无遗漏字符
    • 打开Xcode中Info.plist的可视化编辑界面,确认该键存在且配置了非空的描述文本
  2. 检查RNPermissions配置兼容性

    • 确认RNPermissions版本与当前React Native版本兼容
    • 若请求的是always权限,除目标键外,需额外添加NSLocationWhenInUseUsageDescription(适配iOS 10及以下),部分旧版RNPermissions还需配置NSLocationAlwaysUsageDescription
    • 检查权限请求代码,确认未请求未配置对应权限键的权限类型
  3. 深度清理与重建项目

    • 删除ios/build文件夹,执行pod install后重新构建项目
    • 确认测试设备/模拟器的iOS版本,部分系统版本对权限键的要求存在差异
    • 排查是否有其他第三方库修改或覆盖了Info.plist的权限配置

内容的提问来源于stack exchange,提问作者xafar dev

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.20 10:23:14