IOS)图片扩展无法保存更改问题

标签 ios objective-c ios-extensions

我正在制作照片扩展程序,但是当我尝试保存更改时(点击完成按钮)。

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

这是我的代码 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 对于这个问题,有人说渲染到 NSData 时,图像的大小需要与 originalImage 不同。所以我尝试了这个,但没有成功。

还有一件事。

有什么方法可以从照片扩展程序打开主机应用程序吗?

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 时它起作用了。

谢谢。

最佳答案

试试这个,

转到“设置”,然后转到“照片和相机”。我将选项从优化 iPhone 存储更改为下载并保留原件。

我认为通常在优化设置下照片会下载回原始照片,然后您就可以编辑了。

希望对你有所帮助。

关于IOS)图片扩展无法保存更改问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41340825/

相关文章:

iOS - 在 Localizable.strings 中用粗体字符串强调

ios - 在 iOS Parse App 中节省流量的最佳方式

ios - 无法从Web动态将图像设置为imageview

ios - 什么是更新CXCallDirectoryExtensionContext标签的正确方法?

ios - 在 WatchKitExtension 中混合 swift 和 objective-c

android - Xamarin.Forms:如何使用 DPI 和权重

ios - 无法在 Collection View 中选择项目,Swift

objective-c - 关闭弹出窗口 - Objective-c

objective-c - 我在哪里可以下载适用于 Xcode 的核心音频 SDK? (似乎不是苹果开发者网站)

ios - App Store 中带有扩展程序的应用程序大小