I'm working on action extension for OS X that edits single image.
Everything works well in TextEdit.app. But image changes has no affect in Mail.app. I'm using this code to return edited image back to host app:
- (IBAction)done:(id)sender
{
NSExtensionItem *outputItem = [[NSExtensionItem alloc] init];
outputItem.attachments = @[self.imageView.image];
NSArray *outputItems = @[outputItem];
[self.extensionContext completeRequestReturningItems:outputItems completionHandler:nil];
}
In extension and in Xcode I can see that image is changing. But after [self.extensionContext completeRequestReturningItems:outputItems completionHandler:nil] nothing happens in Mail.app.
Here's project:
https://github.com/derpoliuk/TestExtensionApp/
I created bug report:
rdar://21358060
I saw that other apps are editing photo in Mail.app (for example Pixelmator - http://www.idownloadblog.com/2015/04/21/pixelmator-repair-tool-extension-mac/). So there's should be something that I'm doing wrong.
Any help would be really appreciated.
Stanislav
To make it work one should pass back NSData in NSItemProvider with kUTTypePNG identifier:
NSImage *image = self.imageView.image;
NSData *imageData = [image TIFFRepresentation];
NSBitmapImageRep *imageRep = [NSBitmapImageRep imageRepWithData:imageData];
NSDictionary *imageProps = @{NSImageCompressionFactor: @1.0};
imageData = [imageRep representationUsingType:NSPNGFileType properties:imageProps];
NSItemProvider *itemProvider = [[NSItemProvider alloc] initWithItem:imageData typeIdentifier:(NSString *)kUTTypePNG];
NSExtensionItem *outputItem = [[NSExtensionItem alloc] init];
outputItem.attachments = @[itemProvider];
[self.extensionContext completeRequestReturningItems:@[outputItem] completionHandler:nil];
Stanislav