1

I try to add IPTC, TIFF and EXIF data to an PHAsset. When I apply changes with the following code snipped I got the mentioned error:

guard let ciImage = CIImage(contentsOf: input.fullSizeImageURL!,  options: [.applyOrientationProperty:true]) else {
    fatalError("Not able to create CIImage from input")
}

//Write the edited image as a JPEG.
do {
    try CIContext().writeJPEGRepresentation(of: ciImage,
                                            to: output.renderedContentURL,
                                    colorSpace: outputImage.colorSpace!,
                                       options: [kCGImageDestinationLossyCompressionQuality as CIImageRepresentationOption:1.0])

} catch let error {
    fatalError("Can't apply metadata to the image: \(error).")
}

PHPhotoLibrary.shared().performChanges({
    let request = PHAssetChangeRequest(for: self.asset!)
    request.contentEditingOutput = output
}, completionHandler: { success, error in
    if !success {
        print("Can't edit the asset: \(error?.localizedDescription)")
    }
}

Error:

[PhotoKit] Original resource choice is only valid for an unadjusted base version

What am I doing wrong? Is there a better way to add IPTC metadata to a PHAsset, resp. UIImage file?

sn3ek
  • 1,929
  • 3
  • 22
  • 32

1 Answers1

0

If found the issue which was in the code before I created the CIImage shown in my question. I deleted the code and instead of overriding the binary data of the CIImage I just use the CIImage to store my changes in the PHAsset / PHAssetLibrary.

sn3ek
  • 1,929
  • 3
  • 22
  • 32
  • I receive this error when trying to update a live photo. Could you provide a bit more detail to your answer? What does your chain look like from `phAsset.requestContentEditingInput` on? – Henrik May 10 '19 at 07:43
  • Could you provide a bit more detail to your answer? – Markus Sep 04 '19 at 00:19