IOS - detection when copying a user to the clipboard - [UIPasteboard generalPasteboard]

quick simple question

when using WebView with some text in it - the user can select a fragment of text from it and click on the UIButton that I created by doing the following:

-(IBAction)copyToClip { NSString *copyClip = [UIPasteboard generalPasteboard].string; NSLog(@"Clip = %@",copyClip); // (works fine) } 

I would like to call the same function without UIButton, so when the user performs the “copy” action, he activates the above code. (I accept the listener)

What would be a suitable listener for this?

+6
source share
1 answer

Use NSNotificationCenter and register for UIPasteboardChangedNotification: http://developer.apple.com/library/IOs/documentation/UIKit/Reference/UIPasteboard_Class/Reference.html#//apple_ref/c/data/UIPasteboardChangedNotification

 [[NSNotificationCenter defaultCenter] addObserver:object selector:@selector(copyToClip) name:UIPasteboardChangedNotification object:nil]; 
+9
source

Source: https://habr.com/ru/post/906480/


All Articles