IOS photo extension finishContentEditingWithCompletionHandler: cannot save changes

The photo extension application has access to both cameras and photos. Everything is in order, but when you click Finish, it cannot save the image.

Standard completion handler code:

- (void)finishContentEditingWithCompletionHandler:(void (^)(PHContentEditingOutput *))completionHandler { // Update UI to reflect that editing has finished and output is being rendered. // Render and provide output on a background queue. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ PHContentEditingOutput *output = [[PHContentEditingOutput alloc] initWithContentEditingInput:self.input]; NSError* error = nil; NSData *renderedJPEGData = UIImageJPEGRepresentation(filtered_ui_image, 1.0); assert(renderedJPEGData != nil); //BOOL written_well = [renderedJPEGData writeToURL:output.renderedContentURL atomically:YES]; BOOL written_well = [renderedJPEGData writeToURL:output.renderedContentURL options:NSDataWritingAtomic error:&error]; assert(written_well); // Call completion handler to commit edit to Photos. completionHandler(output); }); } 

renderedJPEGData not nil ,
error - nil , so the function [NSData writeToURL] was successful,
written_well is YES ,

when debugging in turn, a warning appears after block completion: enter image description here

output.renderedContentURL /private/var/mobile/Containers/Data/PluginKitPlugin/509C1A04-D414-4DB7-B1E6-83C47FC88BC9/tmp/blah_blah_name.JPG

So, I have permissions, debug does not show errors, what can I try to determine the cause of the problem?

+8
source share
2 answers

As with iOS 10, these settings must have at least one byte. This is a breaking change from iOS 9, where these settings can be zero. I tested this on both iOS 9 and iOS 10 to confirm.

Additional documentation: https://developer.apple.com/reference/photos/phcontenteditingoutput/1518684-adjustmentdata

 PHContentEditingOutput* output = [[PHContentEditingOutput alloc] initWithContentEditingInput:self.input]; NSMutableData* adjustmentData = [NSMutableData data]; uint8_t byte = 1; [adjustmentData appendBytes:&byte length:1]; output.adjustmentData = [[PHAdjustmentData alloc] initWithFormatIdentifier:@"com.yourcompany.yourapp" formatVersion:@"1.0f" data:adjustmentData]; 
+6
source

Although the header implies that the Data setting may be zero, the documentation states:

If you are writing new resource content to the URL specified by the renderedContentURL property, you must also provide a new, different PHAdjustmentData object that describes your editing. Passing a pre-existing configuration data object (which describes earlier editing) leads to undefined behavior.

So do something like this before calling the completion handler:

 output.adjustmentData = [[PHAdjustmentData alloc] initWithFormatIdentifier:@"com.whatever.app" formatVersion:@"1.0" data:[NSData data]]; 
+1
source

All Articles