Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS: UIPasteboard setImage: fails on iOS6 and/or Xcode 4.5

Update: Added bug 12408800 on Apple's site.


I am copying some one or multiple UIImage to the UIPasteboard, and it's been working like gangbusters.. until my phone upgraded to iOS 6.

  • Xcode 4.5 with iOS 5.1 - OK
  • Xcode 4.4 with iOS 6.0 - Also OK (according to this post)
  • Xcode 4.5 with iOS 6.0 - FAIL

(also tested distributing via TestFlight, for what it's worth - still fails)

Here's my code (super basic, etc):

// add image to clipboard
UIImage *image = [[UIImage imageNamed:@"testimage"];
[[UIPasteboard generalPasteboard] setPersistent:YES];
[[UIPasteboard generalPasteboard] setImage:image];

And here is what happens when I try to paste in an MMS/iMessage window (sorry for huge screenshot; retina display..):

screenshot_of_failure

..and an example of a failure on the Messages sample app in the iOS6 simulator (see the two question marks..?):

another screenshot!

Like I said, the above code has been working for ages, so I'm sure this is something new.

Any thoughts? On the linked post, the author suggests re-compiling on an old version of Xcode - but wouldn't that cause other iOS6 libraries to stop working?

like image 909
toblerpwn Avatar asked Sep 22 '12 03:09

toblerpwn


3 Answers

This works for me on Xcode 4.5 for my iOS 6 devices.

UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];        
NSData *imgData = UIImagePNGRepresentation(@"image");
[pasteboard setData:imgData forPasteboardType:[UIPasteboardTypeListImage objectAtIndex:0]];
like image 144
rob1302 Avatar answered Sep 19 '22 20:09

rob1302


For only one image, you should use:

#import <MobileCoreServices/UTCoreTypes.h>

For JPEG:

NSData *jpegData = UIImageJPEGRepresentation(image, 1.0);
[[UIPasteboard generalPasteboard] setData:jpegData forPasteboardType:(id)kUTTypeJPEG];

or For PNG:

NSData *pngData = UIImagePNGRepresentation(image);
[[UIPasteboard generalPasteboard] setData:pngData forPasteboardType:(id)kUTTypePNG];

and avoid indexing directly in UIPasteboardTypeListImage.

like image 43
Francois Robert Avatar answered Sep 18 '22 20:09

Francois Robert


I sent an email about this issue to Apple Developer Technical Support and I got this reply:

Thank you for contacting Apple Developer Technical Support. Our engineers have reviewed your request and have determined that this would be best handled as a bug report.

Please submit a complete bug report regarding this issue using the Bug Reporter tool at http://bugreport.apple.com.

So it is a bug for sure...

like image 36
iTarek Avatar answered Sep 21 '22 20:09

iTarek