Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS SDK getting clipboard text on application load

I would like to get the text copied to clipboard when application launching.

I can use following text to get the available text from clipboard. But I need to use this value in a different viewcontroller. How can I pass this value to my viewcontroller?

- (void)applicationDidBecomeActive:(UIApplication *)application {

    NSLog([UIPasteboard generalPasteboard].string);

}
like image 401
Rukshan Avatar asked Aug 04 '12 12:08

Rukshan


1 Answers

A much better way of handling this would be to add an observer (in the view controller) for the UIApplicationDidBecomeActiveNotification event. That way you avoid the unnecessary coupling between the app delegate and the view controller.

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(getClipboardString:)
                                             name:UIApplicationDidBecomeActiveNotification object:nil];

Edit: Don't forgot to remove the observer when the view controller is removed:

[[NSNotificationCenter defaultCenter] removeObserver:self];
like image 198
Arvid Janson Avatar answered Nov 11 '22 16:11

Arvid Janson