在尝试将原始照片及其备用照片保存到iOS相册时出现3300错误



我发现它在不传递alterPhoto时执行正常。这是我的代码

let options = PHAssetResourceCreationOptions()
options.shouldMoveFile = true
PHPhotoLibrary.shared().performChanges{
let creationRequest = PHAssetCreationRequest.forAsset()
let options = PHAssetResourceCreationOptions()
options.shouldMoveFile = true
creationRequest.addResource(with: .photo, fileURL: self.rawFileURL!, options: options)
if let a = alterPhoto{
creationRequest.addResource(with: .alternatePhoto, data: a, options: nil)
}
}completionHandler: { s, e in
print(e)
}

这是apple自己的文档中的代码,它不是一个完整的项目,而是一篇包含代码片段的文章:https://developer.apple.com/documentation/avfoundation/photo_capture/capturing_photos_in_raw_and_apple_proraw_formats

PHPhotoLibrary.shared().performChanges {

// Save the RAW (DNG) file as the main resource for the Photos asset.
let options = PHAssetResourceCreationOptions()
options.shouldMoveFile = true
creationRequest.addResource(with: .photo, 
fileURL: rawFileURL, 
options: options)
// Add the compressed (HEIF) data as an alternative resource. 
let creationRequest = PHAssetCreationRequest.forAsset()
creationRequest.addResource(with: .alternatePhoto, 
data: compressedData, 
options: nil)

} completionHandler: { success, error in
// Process the Photos library error.
}
}

我真的不知道为什么。

我遇到了同样的问题,但能够通过切换HEIF和RAW的顺序来使其工作:将HEIF设置为主要,RAW设置为备用:

PHPhotoLibrary.shared().performChanges {
// Add the compressed (HEIF) data as the main resource for the Photos asset. 
let creationRequest = PHAssetCreationRequest.forAsset()
creationRequest.addResource(with: .photo, 
data: compressedData, 
options: nil)
// Save the RAW (DNG) file an alternate resource for the Photos asset.
let options = PHAssetResourceCreationOptions()
options.shouldMoveFile = true
creationRequest.addResource(with: .alternatePhoto, 
fileURL: rawFileURL, 
options: options)

} completionHandler: { success, error in
// Process the Photos library error.
}
}