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);
}
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];