iOS:UIPasteboard setImage:在iOS6和/或Xcode 4.5上失败

更新:在Apple网站上添加了错误12408800。


我正在将一个或多个UIImage复制到UIPasteboard,它一直在工作,直到我的手机升级到iOS 6。

  • iOS 5.1的Xcode 4.5 – 好的
  • Xcode 4.4 with iOS 6.0 – 也行 ( 根据这篇文章 )
  • iOS 6.0的Xcode 4.5 – 失败

(还测试了通过TestFlight分发,它的价值 – 仍然失败)

这是我的代码(超级基本等):

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

以下是当我尝试粘贴MMS / iMessage窗口时发生的情况(对不起巨大的屏幕截图;视网膜显示……):

screenshot_of_failure

..以及iOS6模拟器中的Messages示例应用程序失败的示例(请参阅两个问号..?):

另一个截图!

就像我说的,上面的代码已经工作了很长时间,所以我相信这是新的东西。

有什么想法吗? 在链接的post中,作者建议重新编译旧版本的Xcode – 但这不会导致其他iOS6库停止工作吗?

对于我的iOS 6设备,这适用于Xcode 4.5。

 UIPasteboard *pasteboard = [UIPasteboard generalPasteboard]; NSData *imgData = UIImagePNGRepresentation(@"image"); [pasteboard setData:imgData forPasteboardType:[UIPasteboardTypeListImage objectAtIndex:0]]; 

对于一个图像,您应该使用:

 #import  

对于JPEG:

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

或对于PNG:

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

并避免直接在UIPasteboardTypeListImage中建立索引。

我向Apple Developer Technical Support发送了一封关于此问题的电子邮件,我收到了以下回复:

感谢您与Apple Developer技术支持联系。 我们的工程师已经审核了您的请求,并确定最好将其作为错误报告处理。

请使用http://bugreport.apple.com上的Bug Reporter工具提交有关此问题的完整错误报告。

所以这肯定是一个错误……