Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS - UIPasteboard not working outside app

I think this is more of an SDK flaw than my apps' but recently I've been trying to use UIPasteboard to copy strings from my app and it works fine to pasting somewhere when I'm inside the app.

When I jump to another app by either pressing the home button or anything like that, I simply don't have the option to paste the copied content.

UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
[pasteboard setString: @"blah" ];
NSLog(@"%@", pasteboard.string);

It will print "blah" in this case, and whenever I quick touch a textfield, it will show the paste option. But if I go to Safari, Notes or Mail It doesn't show me that option.

Also, If I copy something from mail and go to my app, I won't see the paste option aswell...

like image 803
Thiago Peres Avatar asked Dec 06 '11 15:12

Thiago Peres


1 Answers

To do a persistent pasteboard between applications you must use

UIPasteboard *pasteboard = [UIPasteboard pasteboardWithName:pasteboardIdentifier create:YES];
[pasteboard setPersistent:YES];
[pasteboard setString:string];
like image 104
lucchiano Avatar answered Sep 24 '22 20:09

lucchiano