ios - 使用 writeToUrl 更新构建中包含的文件(在应用程序容器 .app 中)

标签 ios objective-c ssl ssl-certificate

我正在尝试使用 writeToUrl 动态更新 SSL 证书,但出现此错误:

// Returns the first certificate in the cert chain
SecCertificateRef certificate = SecTrustGetCertificateAtIndex(serverTrust, 0);

// Returns a DER representation of a certificate given a certificate object.
NSData * remoteCertificateData = CFBridgingRelease(SecCertificateCopyData(certificate));

NSError *error;
BOOL didUpdateCertif = [remoteCertificateData writeToURL:localCertificateUrl options:NSDataWritingAtomic error:&error];

localCertificateUrl 的值类似于 file:///var/containers/Bundle/Application/79A3FE24-FA18-4DB9-9DDD-ED2135B47C5A/App-Name.app/certificate .cer.

但是我得到这个错误

Error Domain=NSCocoaErrorDomain Code=513 "You don’t have permission to save the file “certif.cer” in the folder “App-Name”." UserInfo={NSFilePath=/var/containers/Bundle/Application/79A3FE24-FA18-4DB9-9DDD-ED2135B47C5A/App-Name.app/certif.cer, NSUnderlyingError=0x170249ae0 {Error Domain=NSPOSIXErrorDomain Code=1 "Operation not permitted"}}

是我做的不对还是无法动态更新构建中包含的文件?

最佳答案

我刚发现你不能写入这个目录。为防止篡改,捆绑目录在安装时进行了签名。写入此目录会更改签名并阻止您的应用启动。

Link to official docs

关于ios - 使用 writeToUrl 更新构建中包含的文件(在应用程序容器 .app 中),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59267278/

相关文章:

objective-c - 创建正则表达式以匹配自定义格式

objective-c - 为什么必须复制 NSBlock 以存储在容器中?

导入 SSL 证书后,Android Emulator 应用程序未连接到网络

iphone - 以编程方式将图像粘贴到图像上

apache - 在tomcat和apache http服务器之间配置SSL

ssl - 即使通过不安全的选项,使用 hackney 发出请求时证书未知

ios - 使用核心数据更新对象会插入一条新记录

ios - 仅在 Objective C 中的 UIView 底部的底角半径和阴影

iphone - 如何以编程方式将 UIButton 调整为文本大小并保持漂亮的填充?

ios - 带有 iAd 横幅的 UITableView 出现奇怪的溢出