2016-12-27 105 views
2

我正在进行图片扩展,但是当我试图保存更改时(完成按钮点击)。IOS)图片扩展无法保存更改问题

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

这是我 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它工作。

谢谢。

回答

0

试试这个,

转到设置,然后照片& CAMERA。我将优化iPhone存储的选项更改为下载&保留原件。

我想通常在Optimize设置下将照片下载回原来的图片,然后允许您进行编辑。

希望它能帮助你。

+0

谢谢,但我从App Store下载的其他已发布的照片​​扩展程序运行良好。我认为这不是iPhone设置的问题 – TKang