我在使用 UIPasteboard 时遇到了一个奇怪的问题。
我正在从 Safari 复制文本,然后在我的应用程序中使用以下代码查看 UIPasteboard 以查看它是否包含任何数据:
[[UIPasteboard generalPasteboard] containsPasteboardTypes:[NSArray arrayWithObject:@"public.utf8-plain-text"]]
它在模拟器上工作正常,但在 iPad 上却无法工作。这是因为字符集问题吗?
最佳答案
由于字符集问题,我遇到了这个问题,但我不确定它仅适用于 IOS 5.0 还是所有版本。但我已经用一个简单的解决方案解决了我的问题,
UIPasteboardTypeListString
[[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/