I'm trying to repeat the example from Apple's documentation in one of my apps, namely I' capturing a photo, editing it and want to save both of them in one asset together with some adjustment data. Apple provides the following code:
[[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
// Make a change request for adding an asset.
PHAssetChangeRequest *changeRequest =
[PHAssetChangeRequest creationRequestForAssetFromImageAtFileURL:originalJPEGFileURL];
// Make a content editing output for use with the change request.
PHObjectPlaceholder *placeholder = changeRequest.placeholderForCreatedAsset;
PHContentEditingOutput *contentEditingOutput =
[[PHContentEditingOutput alloc] initWithPlaceholderForCreatedAsset:placeholder];
// Apply content adjustments to the newly created asset.
contentEditingOutput.adjustmentData = adjustmentData;
[adjustedJPEGData writeToURL:contentEditingOutput.renderedContentURL atomically:YES];
changeRequest.contentEditingOutput = contentEditingOutput;
} completionHandler:^(BOOL success, NSError *error) {
if (!success) NSLog(@"Can't create asset: %@", error);
}];
Unfortunately I'm constantly getting Error code -1. Did anyone successfully stored the edited image alongside original one while the asset is just creating?
UPDATE 1: This happens only when asset contains a depth info :-/
UPDATE 2: Hmm, things getting worse. I've tried on my iPhone the Apple's app called UsingPhotosFramework and it also doesn't work. I also noticed that I can perform edits using Photos and once I have some edits of the asset both mine and Apple's app work. When asset is reverted back to origin (means no more adjustment data or fullSizePhoto exists) both apps stop working. Snapseed still works on any images.
Ok, the issue has been resolved. The problem was due to edited image had a "wrong" orientation. According to Apple's documentation edited image must be properly oriented (according to its orientation tag for example) and Orientation tag must be set to 1, which apparently CIImage is not doing even after using .oriented method.