-[PHContentEditingOutput initWithPlaceholderForCreatedAsset:] not working with assets in an orientation other than UIImageOrientationUp (default)

Number:rdar://24591429 Date Originated:February 11 2016
Status:Open Resolved:No
Product:iOS SDK Product Version:9.0.2
Classification:Other Bug Reproducible:Yes
When submitting a creation request (-[PHAssetChangeRequest creationRequestForAssetFromImage:]), and modifying the contentEditingOutput of that request. The original image cannot have an orientation other than UIImageOrientationUp. Otherwise the changes will fail, with error -1. 

UIImage *ImgRed = [UIImage imageWithCGImage: Red scale: 1.0f orientation: UIImageOrientationDown]; //doesn't seem to matter what the orientation is as long as the original is UIImageOrientationUp
UIImage *ImgBlue = [UIImage imageWithCGImage: Blue scale: 1.0f orientation: UIImageOrientationDown]; //only works if orientation is UIImageOrientationUp

[[PHPhotoLibrary sharedPhotoLibrary] performChanges: ^{
    PHAssetChangeRequest *ChangeRequest = [PHAssetChangeRequest creationRequestForAssetFromImage: ImgBlue];
    PHContentEditingOutput *EditingOutput = [[[PHContentEditingOutput alloc] initWithPlaceholderForCreatedAsset: ChangeRequest.placeholderForCreatedAsset] autorelease];
    EditingOutput.adjustmentData = [[[PHAdjustmentData alloc] initWithFormatIdentifier: @"com.test.colour" formatVersion: @"1.0.0" data: [NSData dataWithBytes: "r" length: 1]] autorelease];
    [UIImageJPEGRepresentation(ImgRed, 1.0) writeToURL: EditingOutput.renderedContentURL atomically: YES];
    ChangeRequest.contentEditingOutput = EditingOutput;
} completionHandler: ^(BOOL success, NSError * _Nullable error){
    if (!success) NSLog(@"%@", error); //will print: 'Error Domain=NSCocoaErrorDomain Code=-1 "(null)"'

If not modifying the contentEditingOutput, then the original image can have any orientation. This is the behaviour that would be expected to be applied in either case.

Steps to Reproduce:
1. Request changes to be applied to the photo library
2. Create a creation request for the image with an orientation other than UIImageOrientationUp
3. Create an editing output object from the placeholder asset
4. Set the adjustment data and save the result image
5. Set the contentEditingOutput

Expected Results:
The completion handler should be passed success. And the modified image (where it's preserved the original + adjustment data) should appear in the photo library.

Actual Results:
The completion handler is passed NO for success, and the error is set to a NSCocoaErrorDomain error with error code -1 and no userInfo. And the image is not in the photo library.

A temporary workaround is to transform the image ourselves so it is oriented in the correct way. In which case we can then use UIImageOrientationUp. However this isn't ideal as it is extra work for the application.



This bug might be fixed in iOS 11 through the CIImageOption value .applyOrientationProperty. Does exactly what you're asking for: picks up the UIImage orientation from the input so that it gets written out correct to the output. No more error in the completion handler.

By mattneub2 at Aug. 8, 2018, 3:35 p.m. (reply...)

Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!