ios - 为什么我的 UIPasteboard 代码不起作用?

标签 ios ipad uipasteboard

我在使用 UIPasteboard 时遇到了一个奇怪的问题。

我正在从 Safari 复制文本,然后在我的应用程序中使用以下代码查看 UIPasteboard 以查看它是否包含任何数据:

[[UIPasteboard generalPasteboard] containsPasteboardTypes:[NSArray arrayWithObject:@"public.utf8-plain-text"]]

它在模拟器上工作正常,但在 iPad 上却无法工作。这是因为字符集问题吗?

最佳答案

由于字符集问题,我遇到了这个问题,但我不确定它仅适用于 IOS 5.0 还是所有版本。但我已经用一个简单的解决方案解决了我的问题,

UIPasteboardTypeListString

http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIPasteboard_Class/Reference.html

 [[UIPasteboard generalPasteboard] containsPasteboardTypes:UIPasteboardTypeListString];
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard]; 
if (pasteboard.string != nil) { [self insertText:pasteboard.string]; }

希望这个答案可以帮助到大家。

关于ios - 为什么我的 UIPasteboard 代码不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8698563/

相关文章:

iphone - 关于 iAd 在 iPad 和 iPhone 上显示的问题

javascript - 将触摸事件分配给 Canvas 中的元素 - iPad

ios - UIImagePickerController与isSourceTypeAvailable的区别: and isCameraDeviceAvailable:

javascript - 无法将文本从 WKWebview 复制到剪贴板

ios - 将带有字体和大小的 NSMutableAttributedString 放入 UIPasteboard 以粘贴到另一个应用程序中

iphone - player.duration 在视频文件的 MPMoviePlayerController 中始终显示为零

iphone - 如何从一个 iPhone 麦克风向另一个 iPhone 扬声器发送和接收实时音频?

iphone - 模型版本控制和数据迁移之间有什么区别?

iphone - 添加到 UIPasteboard 的图像在 TWITTER 中不显示 PASTE 选项

iphone - AV播放器状态?