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?