首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法在iOS 15.1中生成实时照片

无法在iOS 15.1中生成实时照片
EN

Stack Overflow用户
提问于 2021-11-04 08:00:01
回答 2查看 197关注 0票数 2

在iOS 15.0中运行良好,但在升级到iOS 15.1后,代码无法正常工作。

代码语言:javascript
复制
_ = 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))

    }

})

有人能帮上忙吗?

EN

回答 2

Stack Overflow用户

发布于 2021-11-05 09:44:42

我也遇到了同样的问题:PHPhotosErrorKey error 3302也就是PHPhotosErrorInvalidResourcePHLivePhoto.request出现了故障。

研究后发现,从iOS15.1开始,包含实时照片id的"{MakerApple}"元数据字段停止写入图像文件元数据,因此livePhoto验证失败,因为LivePhoto的图像和电影部分的标识符需要相同。

在尝试了不同的方法后,我发现IOS没有在"{MakerApple}"图像上写入JPEG元数据。它只能在苹果自己的文件格式上做到这一点。(即heic)。(从IOS 15.1开始)

要解决此问题,请将您的图像部分编码为heic"{MakerApple}"元数据将被保留。您可以使用以下内容来实现此目的:

代码语言:javascript
复制
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)

为了获取heic数据,我使用了Leo Dabus here提供的UIImage扩展

票数 2
EN

Stack Overflow用户

发布于 2021-11-04 15:00:22

代码语言:javascript
复制
    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
    }
票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69835952

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档