IOS) Photo Extension Unable To Save Changes Issue

女生的网名这么多〃 提交于 2019-12-22 09:59:16

问题


I am making Photo Extension, but when I am trying to save changes(Done button Tapped).

Alert Message Says "Unable to Save Changes" - 'An Error occurred while saving. Please try again later.'

This is my code for finishContentEditingWithCompletionHandler:completionHandler

- (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(QOS_CLASS_DEFAULT, 0), ^{
        // Create editing output from the editing input.
        PHContentEditingOutput *output = [[PHContentEditingOutput alloc] initWithContentEditingInput:self.input];
        NSURL *originalImageURL = self.input.fullSizeImageURL;
        //Apply filter
        CIFilter *appliedFilter = [CIFilter filterWithLUT:self.presetFilterNameArray[self.currentAppliedFilterIndex] originalLUT:@"LUT-ORG-512" dimension:64 alpha:self.filterAlphaSlider.value CIContext:self.ciContext];
        UIImage *filteredOriginalImage = [self filterApply:[UIImage imageWithContentsOfFile:originalImageURL.path] filter:appliedFilter];
        //Apply orientation
        filteredOriginalImage = [UIImage imageWithCGImage:filteredOriginalImage.CGImage scale:filteredOriginalImage.scale orientation:self.input.fullSizeImageOrientation];

        // Provide new adjustments and render output to given location.
        NSData *archiver = [NSKeyedArchiver archivedDataWithRootObject:self.presetFilterNameArray[self.currentAppliedFilterIndex]];
        output.adjustmentData = [[PHAdjustmentData alloc] initWithFormatIdentifier:@"com.fantagram.BetterAndBetter.TKPhotoExtension" formatVersion:@"1.0" data:archiver];

        NSData *renderedJPEGData = UIImageJPEGRepresentation(filteredOriginalImage, 1.0f);
        if([renderedJPEGData writeToURL:output.renderedContentURL atomically:YES]){
            NSLog(@"success to write");
        }
        else{
            NSLog(@"fail to write");
        }

        NSLog(@"%@", output);
        // Call completion handler to commit edit to Photos.
        completionHandler(output);

        // Clean up temporary files, etc.
    });
}

Previous Answer for this issue, someone said that when rendering to NSData, the size of image need to be different with originalImage. So I tried this, but didn't work.

One More Thing.

Are there any way to open the host app from photo extension?

self.extensionContext openURL: didn't work(As I know of It only works in Today Extension.)

UIResponder *responder = self;
        while(responder){
            if([responder respondsToSelector:@selector(openURL:)]){
                dispatch_async(dispatch_get_main_queue(), ^{
                       [responder performSelector:@selector(openURL:) withObject:[NSURL URLWithString:(MY_URL_Schemes)]];     
                });
            }
            responder = [responder nextResponder];
        }

above code also didn't work. It worked when I used it share extension.

Thanks.


回答1:


Try this,

Go to SETTINGS then PHOTOS & CAMERA. I changed the options from Optimize iPhone Storage, to DOWNLOAD & KEEP ORIGINALS.

I think Normally under the Optimize setting photos are downloaded back to the original and then you are allowed to edit.

Hope it will help you.



来源:https://stackoverflow.com/questions/41340825/ios-photo-extension-unable-to-save-changes-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!