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.
(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..):
..and an example of a failure on the Messages sample app in the iOS6 simulator (see the two question marks..?):
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?
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]];
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.
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...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With