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

问题描述 投票:0回答:1

我发现在不传递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)
        }

这是苹果自己文档中的代码,该地址不是一个完整的项目,而是一篇带有代码片段的文章: 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.
        }
    }

我真的不知道为什么。

ios swift iphone camera avfoundation
1个回答
0
投票

我遇到了同样的问题,但可以通过切换 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.
        }
    }
© www.soinside.com 2019 - 2024. All rights reserved.