Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copying .gif images to clipboard using UIPasteboard through code [iOS]

I want to copy .gif images to clipboard, so as user can paste that gif images from application to mails, etc...

I have tried :-

NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://fc05.deviantart.net/fs37/f/2008/283/a/b/KaleidoCoils_animated__gif_by_1389AD.gif"]];
UIPasteboard *pasteBoard=[UIPasteboard generalPasteboard];
[pasteBoard setImage:[UIImage imageWithData:data]];

but it copies in format of .png and not .gif. How can I copy .gif image with its animation to clipboard which can be used as paste option in other application?

Application https://itunes.apple.com/us/app/animated-3d-emoji+emoticons/id429348043?mt=8 already does this.

Please help me.

Thanks in advance

like image 382
P.J Avatar asked Apr 16 '13 09:04

P.J


1 Answers

I found solution for same :-

This is my code which helped me:-

@import MobileCoreServices;

NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://fc05.deviantart.net/fs37/f/2008/283/a/b/KaleidoCoils_animated__gif_by_1389AD.gif"]];
UIPasteboard *pasteBoard=[UIPasteboard generalPasteboard];
[pasteBoard setData:data forPasteboardType:(__bridge NSString *)kUTTypeGIF];

@"com.compuserve.gif" comes from http://www.escape.gr/manuals/qdrop/UTI.html

Hope this helps someone... :)

like image 179
P.J Avatar answered Oct 26 '22 14:10

P.J