Reputation: 24810
Suppose - User has selected & copied some text in textField/textView/webView.
Now I want to Log the copied text, But don't know how?
How is it possible?
Sagar
Upvotes: 1
Views: 490
Reputation: 274
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
if ([pasteboard containsPasteboardTypes: [NSArray arrayWithObject:@"public.utf8-plain-text"]]) {
NSLog(@"WE gots a string which is: %@", pasteboard.string);
}
Hope this help! ;)
Upvotes: 3
Reputation: 11
I'm new to objective-c development so I might be mistaking but shouldn't the NSLog row be below the "[appPasteBoard..."-row? You log the text before it is actually written to the pasteboard.
It is a brilliant example in any case and I used it with a little tweak. I wanted to use the general pasteboard so I ended up with this:
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
pasteboard.persistent = YES;
NSString *yourCopiedText = @"YOUR TEXT HERE";
[pasteboard setString:yourCopiedText];
NSLog(@"\n String sent to pasteboard: %@",pasteboard.string);
Hope it can help anyone and thanks Neurofluxation for the example!
Regards Henrik
Upvotes: 1
Reputation: 10715
Ok, here you go Sagar... It would be wise for you to research how this works though:
This code to Copy strings to the pasteBoard:
-(IBAction)copyStringToPasteBoard{
UIPasteboard *appPasteBoard = [UIPasteboard pasteboardWithName:@"CopyFrom" create:YES];
appPasteBoard.persistent = YES;
NSString *yourCopiedText = @"YOUR TEXT HERE";
NSLog(@"\n Your String: %@",appPasteBoard.string);
[appPasteBoard setString:textView.text];
}
I hope this is more specific for you, please vote me up ^.^
Upvotes: 1
Reputation: 10715
My guess would be to use the UIPasteBoard function: http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIPasteboard_Class/Reference.html
Hope that helps!
Upvotes: 1