iOS Error Domain=PHPhotosErrorDomain Code=3300

文章讲述了在使用AVCapturePhoto将数据保存到PHPhotoLibrary时遇到的错误,原因在于资源类型设置错误。解决方案包括正确使用PHAssetResourceTypeAlternatePhotoforRAW文件,以及确保PHAssetCreationRequest和PHAssetResourceCreationOptions对象仅初始化一次。
摘要由CSDN通过智能技术生成
AVCapturePhoto的数据保存到 PHPhotoLibrary的时候报错Error Domain=PHPhotosErrorDomain Code=3300

解决代码(也可以使用addResourceWithType:data:options:来添加数据到request,JEPG的实测可以,raw的不确定):

[PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) {
PHAssetCreationRequest *request = [PHAssetCreationRequest creationRequestForAsset];
PHAssetResourceCreationOptions *options = [[PHAssetResourceCreationOptions alloc] init];

// self.rawFileURL is your custom URL, you'd better to use "[yourFileDirectoryAndFileName URLByAppendingPathExtension:@"DNG"];" to express format
[request addResourceWithType:PHAssetResourceTypeAlternatePhoto fileURL:self.rawFileURL options:options];

// self.compressedFileURL is your custom URL, you can choose some compress format to save. It's optional, but if you invoke "AVCapturePhotoSettings photoSettingsWithRawPixelFormatType:processedFormat:",you must pass parameter "processedFormat" but not need to invoke addResourceWithType:fileURL:options: as below:
if (self.compressedFileURL) {
    [request addResourceWithType:PHAssetResourceTypePhoto fileURL:self.compressedFileURL options:nil];
}

 运行截图:

问题原因:保存RAW到resource的时候用了PHAssetResourceTypePhoto,但是PHAssetResourceType的文档显示raw用PHAssetResourceTypeAlternatePhoto(下图最后一行).这和苹果的官方示例是不一样的,注意注意!

如果你只想保存RAW文件,你也需要调用"AVCapturePhotoSettings photoSettingsWithRawPixelFormatType:processedFormat:",注意你必须传递参数给processedFormat,但接下来不需要调用addResourceWithType:fileURL:options:添加有损格式(例如JPEG)到照片库PHPhotoLibrary。

还有PHAssetCreationRequest和PHAssetResourceCreationOptions对象必须只新建一次,如果多次alloc和init这两个对象将导致问题。(好像是code=3301)

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值