Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone Copy Something to Clipboard via Code

Tags:

copy

iphone

I was wondering if I could copy some text to the iphone keyboard via code - I.E. They press a button named "Copy Link to Clipboard" and it would copy a link to the Clipboard?

Thanks.

like image 962
Christian Stewart Avatar asked Oct 30 '10 20:10

Christian Stewart


People also ask

How do you copy content to clipboard?

Open the file that you want to copy items from. Select the first item that you want to copy, and press CTRL+C. Continue copying items from the same or other files until you have collected all of the items that you want. The Office Clipboard can hold up to 24 items.

Can you save things to clipboard on iPhone?

When you copy something on your iPhone, iPad, or Mac, it's saved to the clipboard, ready to be pasted anywhere. However, your previous clipboard is overwritten and lost forever if you copy something else!


2 Answers

A normal string would be copied via

UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
pasteboard.string = @"my test string";

a URL via e.g

UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
pasteboard.URL = [NSURL URLWithString:@"http://stackoverflow.com/questions/4060471/iphone-copy-something-to-clipboard-via-code"];
like image 93
H6. Avatar answered Nov 11 '22 00:11

H6.


UIPasteboard is what you need:

http://mobileorchard.com/new-in-iphone-30-tutorial-series-part-3-copy-paste-with-uipasteboard/

like image 36
MusiGenesis Avatar answered Nov 11 '22 00:11

MusiGenesis