9

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

P.J
  • 6,547
  • 9
  • 44
  • 74

1 Answers1

23

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... :)

brynbodayle
  • 6,546
  • 2
  • 33
  • 49
P.J
  • 6,547
  • 9
  • 44
  • 74
  • HI @P.J this solution is working fine. But converting the URL to the NSData is taking more time. Have you any idea how to boost it?? – Ramakrishna Oct 22 '16 at 04:03