【问题标题】:IOS) Photo Extension Unable To Save Changes IssueIOS)照片扩展无法保存更改问题
【发布时间】:2016-12-27 07:23:34
【问题描述】:

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

警报消息显示“无法保存更改”-“发生错误” 在保存的同时。请稍后再试。'

这是我的代码 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不同。所以我尝试了这个,但没有奏效。

还有一件事。

有没有办法从照片扩展打开主机应用程序?

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

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

谢谢。

【问题讨论】:

  • 关于您的第二个问题:它在文档中,但是可以从扩展中使用的 iOS SDK 的 API 是有限的。特别是,整个UIApplication 业务超出了界限(这是有道理的:您的扩展只是一个共享框架,被另一个应用程序使用,它拥有sharedInstanceUIApplication)。因此,我认为您不能从扩展程序中启动容器应用程序。
  • 我根据Apple的示例代码创建了一个最小的应用程序,只是它尝试将原始图像保存不变; finishContentEditing: 的其余部分与 Apple 的代码相同。我已经记录了编辑会话开始时传递的PHContentEditingInput 数据的所有属性,我很快注意到当fullSizeImageOrientation 的值为6(又名CGImagePropertyOrientation.right)时,保存总是失败,这在某种程度上适用于所有照片我接受纵向。一旦我找到解决方法或解决方案,我会发布一个。回答。

标签: ios objective-c ios-extensions


【解决方案1】:

试试这个,

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

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

希望对你有所帮助。

【讨论】:

  • 谢谢,但我从 App Store 下载的其他已发布照片扩展程序运行良好。我认为这不是 iPhone 设置的问题
  • 我遇到了同样的问题。商店中的一些应用程序也能体验到它,有些则没有。 Apple 的示例代码也受此影响。它似乎出现在特定的照片上。
  • @TKang 我下载了几个扩展,还有苹果自己的示例代码。令人惊讶的是,Apple 的代码和商店中的一些第三方扩展(但不是全部)也遇到了这个问题,并附有一些照片。 BitCam 是一个特别强大的,似乎总是能够成功保存的。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-04-06
  • 1970-01-01
  • 1970-01-01
  • 2014-12-09
  • 2019-02-22
  • 2016-12-19
相关资源
最近更新 更多