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

非 Y 不嫁゛ 提交于 2019-12-20 14:10:44

问题


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

..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?


回答1:


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]];



回答2:


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.




回答3:


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



来源:https://stackoverflow.com/questions/12540429/ios-uipasteboard-setimage-fails-on-ios6-and-or-xcode-4-5

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!