0

I want to implement a clipboard app using UIPasteboard, which can copy plain text and also rich format , web content in to the pasteboard , and then display on my TextView or WebView. how can i do that?

i have following code and it can get the plain text , but what if i copy a web content?

if ([pasteboard containsPasteboardTypes:[NSArray arrayWithObjects:@"public.utf8-plain-text", @"public.text", nil]]){
    if (![_contentList containsObject:pasteboard.string]){
        NSLog(@"String representation present: %@", pasteboard.string);
        [self addContentList:pasteboard.string];
        [pasteboard setValue:@"" forPasteboardType:UIPasteboardNameGeneral];
    }

}
zolibra
  • 532
  • 6
  • 16

1 Answers1

0

Try using UIPasteboardTypeListString instead

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

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

lostInTransit
  • 70,519
  • 61
  • 198
  • 274
  • i think this can only catch a string , what if i copy a web content ? such as html ? – zolibra Jun 04 '13 at 01:28
  • See the answer here for rich text - http://stackoverflow.com/a/12603189/46297 Not sure if it will work when copying from a web page though. – lostInTransit Jun 04 '13 at 03:46
  • This not the cases, what i want is get the content from UIPasteboard, but not set content in it. – zolibra Jun 21 '13 at 23:51