在iOS 15.0中运行良好,但在升级到iOS 15.1后,代码无法正常工作。
_ = PHLivePhoto.request(withResourceFileURLs: [pairedVideoURL, pairedImageURL], placeholderImage: nil, targetSize: CGSize.zero, contentMode: PHImageContentMode.aspectFit, resultHandler: { (livePhoto: PHLivePhoto?, info: [AnyHashable : Any]) -> Void in
if let isDegraded = info[PHLivePhotoInfoIsDegradedKey] as? Bool, isDegraded {
return
}
DispatchQueue.main.async {
completion(livePhoto, (pairedImageURL, pairedVideoURL))
}
})有人能帮上忙吗?
发布于 2021-11-05 09:44:42
我也遇到了同样的问题:PHPhotosErrorKey error 3302也就是PHPhotosErrorInvalidResource,PHLivePhoto.request出现了故障。
研究后发现,从iOS15.1开始,包含实时照片id的"{MakerApple}"元数据字段停止写入图像文件元数据,因此livePhoto验证失败,因为LivePhoto的图像和电影部分的标识符需要相同。
在尝试了不同的方法后,我发现IOS没有在"{MakerApple}"图像上写入JPEG元数据。它只能在苹果自己的文件格式上做到这一点。(即heic)。(从IOS 15.1开始)
要解决此问题,请将您的图像部分编码为heic,"{MakerApple}"元数据将被保留。您可以使用以下内容来实现此目的:
let assetIdentifier = UUID()
guard
let destintation = CGImageDestinationCreateWithURL(imageURL as CFURL, UTType.heic.identifier as CFString, 1, nil),
let data = staticUIImage!.heic,
let imageSource = CGImageSourceCreateWithData(data as CFData, nil)
else {
return
}
var metadata = CGImageSourceCopyProperties(imageSource, nil) as! [String : Any]
let makerNote = ["17" : assetIdentifier.uuidString]
metadata[String(kCGImagePropertyMakerAppleDictionary)] = makerNote
CGImageDestinationAddImageFromSource(destintation, imageSource, 0, metadata as CFDictionary)
CGImageDestinationFinalize(destintation)发布于 2021-11-04 15:00:22
func addAssetID(_ assetIdentifier: String, toImage imageURL: URL, saveTo destinationURL: URL) -> URL? {
let kFigAppleMakerNote_AssetIdentifier = "17"
let image = UIImage(contentsOfFile: imageURL.path)
let imageRef = image?.cgImage
let imageMetadata = [kCGImagePropertyMakerAppleDictionary: [kFigAppleMakerNote_AssetIdentifier: assetIdentifier]]
let cfUrl = destinationURL as CFURL
let dest = CGImageDestinationCreateWithURL(cfUrl, kUTTypeJPEG, 1, nil)
CGImageDestinationAddImage(dest!, imageRef!, imageMetadata as CFDictionary)
_ = CGImageDestinationFinalize(dest!)
return destinationURL
}https://stackoverflow.com/questions/69835952
复制相似问题