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

react-native-qrcode-scanner在iOS端无法运行的解决方案求助

iOS 端运行 react-native-qrcode-scanner 解决方案

1. 修正 Podfile 权限配置

react-native-permissions 4.x 配合 RN 0.73.x 时,需确保主依赖与权限子依赖都正确引入,替换你之前的配置为:

permissions_path = '../node_modules/react-native-permissions/ios'
pod 'RNPermissions', :path => '../node_modules/react-native-permissions'
pod 'Permission-Camera', :path => "#{permissions_path}/Camera"

注意:不要给路径添加 .podspec 后缀,否则会导致 pod 解析失败。

2. 配置 Info.plist 相机权限描述

iOS 要求必须声明权限使用说明,否则会无法获取相机权限。在 ios/[你的项目名]/Info.plist 中添加:

<key>NSCameraUsageDescription</key>
<string>需要访问相机以扫描二维码</string>

3. 清理依赖缓存并重新安装

RN 0.73.x 与旧版本依赖可能存在缓存冲突,执行以下命令清理后重装:

# 清理 node_modules 和缓存
rm -rf node_modules package-lock.json
npm install

# 清理 iOS 依赖并重装
cd ios
pod deintegrate
pod install --repo-update
cd ..

# 清理 RN 缓存
npx react-native clean

4. 调整 Xcode 项目配置

  • 打开 Xcode,进入项目 Build Settings,将 Enable Bitcode 设置为 No(react-native-qrcode-scanner 1.5.5 不支持 Bitcode)
  • 确认 Deployment Target 不低于 iOS 11.0(该库的最低系统要求)

5. 修正权限请求逻辑

确保使用 react-native-permissions 的正确 API 请求相机权限:

import { check, request, PERMISSIONS, RESULTS } from 'react-native-permissions';

const handleScan = async () => {
  const status = await check(PERMISSIONS.IOS.CAMERA);
  if (status === RESULTS.DENIED) {
    const result = await request(PERMISSIONS.IOS.CAMERA);
    if (result !== RESULTS.GRANTED) {
      alert('请在设置中开启相机权限');
      return;
    }
  }
  // 启动扫码组件
};

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.21 13:07:13