On May 16, 2014, at 10:26 AM, Charles Carver wrote:

>> I'm pretty new to Objective-C, but have been mostly understanding everything 
>> so far. I am stuck, however, on trying to share an animated GIF through 
>> NSSharingService.
>> 
>> I am attaching the image like so, where “image" is a string containing the 
>> URL of an animated GIF (http://i.imgur.com/V8w9fKt.gif, for example):
>> 
>> NSImage *imageData = [[NSImage alloc] initWithContentsOfURL:[NSURL 
>> URLWithString:image]];
>> NSArray *shareItems = [NSArray arrayWithObjects:imageData, @“Text", nil];
>> NSSharingService *service = [NSSharingService 
>> sharingServiceNamed:NSSharingServiceNameComposeMessage];
>> service.delegate = self;
>> [service performWithItems:shareItems];
>> 
>> When the code is run and the message is sent, however, the image gets sent 
>> as a PNG file instead of a GIF.

Instead of putting an NSImage into the list, try creating an NSPasteboardItem 
and setting its data to be the image data and its type to kUTTypeGIF:

    NSData* data = [NSData dataWithContentsOfURL:[NSURL URLWithString:image]];
    NSPasteboardItem* item = [[NSPasteboardItem alloc] init];
    [item setData:data forType:(__bridge NSString*)kUTTypeGIF];
    NSArray *shareItems = [NSArray arrayWithObjects:item, @“Text", nil];
    …

It may still end up as a PNG because the pasteboard server will translate from 
any known image type to the most common interchange formats, and the receiving 
end gets to pick its preferred type.

If that still doesn't work, you can try putting either the original URL into 
the shareItems array or the file URL from a locally-saved file.

Regards,
Ken


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to