所有通知都在AppDelegate
中处理,但通常在顶级控制器中需要它们才能对当前视图执行某些操作。我怎么能这样做?
答案 0 :(得分:1)
让您的UIVIewController
符合协议UIApplicationDelegate
。然后使用此处回答的代码访问顶级视图控制器:Get the current displaying UIViewController on the screen in AppDelegate.m。
假设您需要在顶部UIViewController
获取远程通知,然后在AppDelegate
中写一下:
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
(UIStoryboard.topViewController() as? UIApplicationDelegate)?.application?(application, didReceiveRemoteNotification: userInfo)
}