小编Mar*_*l T的帖子

修改现有phAsset中的元数据似乎不起作用

在我的应用程序中,我想让它成为可能,用户为他的PhotoLibrary中的任何图像设置一个从0到5的StarRating.我的研究表明,有几种方法可以完成这项工作:

使用新的PHPhotoLibrary保存exif元数据

Swift:自定义相机使用图像保存已修改的元数据

使用Photokit使用元数据编写照片

大多数这些答案都在创建一个新的照片.我的片段现在看起来像这样:

let options = PHContentEditingInputRequestOptions()
options.isNetworkAccessAllowed = true

self.requestContentEditingInput(with: options, completionHandler: {
            (contentEditingInput, _) -> Void in

    if contentEditingInput != nil {

        if let url = contentEditingInput!.fullSizeImageURL {
            if let nsurl = url as? NSURL {
                if let imageSource = CGImageSourceCreateWithURL(nsurl, nil) {
                    var imageProperties = CGImageSourceCopyPropertiesAtIndex(imageSource, 0, nil) as Dictionary?
                    if imageProperties != nil {
                        imageProperties![kCGImagePropertyIPTCStarRating] = rating as AnyObject

                        let imageData = NSMutableData(contentsOf: url)
                        let image = UIImage(contentsOfFile: url.path)

                        let destination = CGImageDestinationCreateWithData(imageData!, CGImageSourceGetType(imageSource)!, …
Run Code Online (Sandbox Code Playgroud)

ios swift photokit phasset

8
推荐指数
1
解决办法
815
查看次数

标签 统计

ios ×1

phasset ×1

photokit ×1

swift ×1