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

iOS手动安装react-native-ssl-pinning后证书验证报错求助

iOS端react-native-ssl-pinning证书报错排查方案

核心排查步骤

针对你遇到的URL unsupport or The certificate for this server is not valid错误,结合RN 0.71.8版本和手动安装依赖的场景,按以下步骤逐一验证:

1. 证书格式与路径校验

  • 确保使用PEM格式证书,若为cer格式,执行命令转换:
    openssl x509 -in certificate.cer -out certificate.pem -outform PEM
    
  • 将证书文件添加到iOS项目Resources目录(右键项目→Add Files to "项目名",勾选Copy items if needed),再检查Build Phases→Copy Bundle Resources中是否包含该证书。

2. 手动集成完整性确认

  • 打开iOS项目Podfile,确认已添加:
    pod 'react-native-ssl-pinning', :path => '../node_modules/react-native-ssl-pinning'
    
    执行pod install --repo-update,确保Pod依赖完全安装。
  • 检查AppDelegate.m/AppDelegate.swift,确认RCTSSLModule已正确注册(部分手动集成场景需手动添加模块注册代码)。

3. RN版本兼容性适配

确认react-native-ssl-pinning版本兼容RN 0.71.8,查看库的package.json中peerDependencies字段,若版本不匹配,尝试升级/降级到适配0.71.x的版本(如v1.5.0及以上版本通常支持RN 0.70+)。

4. 证书链匹配验证

  • 访问****.com导出根CA证书(而非服务器证书或中间证书),确保项目中使用的是证书链最顶层的根证书。
  • 执行openssl s_client -connect ****.com:443查看证书链,确认你使用的证书在链中存在。

5. 代码使用方式检查

确保代码中证书名称配置正确(不带文件后缀,iOS区分文件名大小写):

import { fetch } from 'react-native-ssl-pinning';

fetch('https://****.com/api', {
  method: 'GET',
  sslPinning: {
    certs: ['certificate'], // 此处为证书文件名(无.pem后缀)
  },
})

6. ATS临时排查(仅测试用)

在Info.plist中添加ATS例外(上线前务必移除),验证是否为ATS配置导致:

<key>NSAppTransportSecurity</key>
<dict>
  <key>NSAllowsArbitraryLoads</key>
  <true/>
</dict>

若关闭ATS后恢复正常,说明核心问题仍在证书配置环节。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.16 14:17:19