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
它工作。
謝謝。
謝謝,但我從App Store下載的其他已發佈的照片擴展程序運行良好。我認爲這不是iPhone設置的問題 – TKang