All notifications are handled in AppDelegate
, but usually they are needed in top controller to perform some actions on current view. How can I do this?
Asked
Active
Viewed 624 times
0

Bartłomiej Semańczyk
- 59,234
- 49
- 233
- 358
1 Answers
1
Make your UIVIewController
conformed to protocol UIApplicationDelegate
. And then get access to the top view controller using code answered here: Get the current displaying UIViewController on the screen in AppDelegate.m.
Let's say you need to get remote notification in your top UIViewController
, then in AppDelegate
you just write:
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
(UIStoryboard.topViewController() as? UIApplicationDelegate)?.application?(application, didReceiveRemoteNotification: userInfo)
}

Community
- 1
- 1

Bartłomiej Semańczyk
- 59,234
- 49
- 233
- 358
-
1Why not post a notification from the `AppDelegate`? Shouldn't ViewControllers do their jobs and not be the app's logic? – rshev Sep 25 '15 at 09:40