Reputation: 205
I am having a weird issue with the UIPasteboard.
I am copying text from Safari, and then in my app looking into UIPasteboard to see if it contains any data using this code:
[[UIPasteboard generalPasteboard] containsPasteboardTypes:[NSArray arrayWithObject:@"public.utf8-plain-text"]]
It's working fine with the Simulator but not working with the iPad. Is this because of any character set issue?
Upvotes: 2
Views: 3928
Reputation: 205
I was having this issue because of character set but i am not sure it was only with the IOS 5.0 or for all version. But i have solved my problem with a simple solution,
UIPasteboardTypeListString
[[UIPasteboard generalPasteboard] containsPasteboardTypes:UIPasteboardTypeListString];
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
if (pasteboard.string != nil) { [self insertText:pasteboard.string]; }
I hope this answer can help anyone.
Upvotes: 4
Reputation: 2808
From my own experiences it appears that in iOS 5 plain text no longer ends up on the pasteboard as public.utf8-plain-text
, but instead as public.text
. Using UIPasteboardTypeListString
instead of explicitly specifying the string will also work.
So I now use the following in my code to detect plain text in the pasteboard:
[[UIPasteboard generalPasteboard] containsPasteboardTypes:[NSArray arrayWithObjects:@"public.utf8-plain-text", @"public.text", nil]]
or
[[UIPasteboard generalPasteboard] containsPasteboardTypes:UIPasteboardTypeListString]
Is it the case you are testing in the simulator against iOS 4.x and your iPad has iOS 5 installed?
Upvotes: 1