iOS)照片扩展名无法保存更改问题 [英] IOS) Photo Extension Unable To Save Changes Issue

查看:761
本文介绍了iOS)照片扩展名无法保存更改问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作照片扩展名,但是当我尝试保存更改时(轻按完成"按钮.)

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.'

这是我的代码 finishContentEditingWithCompletionHandler:completionHandler

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.
    });
}

这个问题的先前答案,有人说渲染到NSData时,图像的大小需要与originalImage不同.所以我尝试了一下,但是没有用.

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.

还有一件事情.

是否可以通过照片扩展程序打开主机应用?

self.extensionContext openURL:不起作用(据我所知,它只能起作用 在今日扩展中.)

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];
        }

以上代码也不起作用.当我使用它share extension时它起作用.

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

谢谢.

推荐答案

尝试一下,

依次转到设置"和照片和照片"相机.我将选项从优化iPhone存储"更改为下载&保持原点.

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.

这篇关于iOS)照片扩展名无法保存更改问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆