画面上の現在UIViewController
は、いくつかのバッジ ビューを設定することによって、APNs からのプッシュ通知に応答する必要があります。しかし、どうすればUIViewController
in メソッドapplication:didReceiveRemoteNotification
: ofを取得できAppDelegate.m
ますか?
self.window.rootViewController
現在の表示を取得するために使用しようとしましたがUIViewController
、それはUINavigationViewController
または他の種類のView Controllerである可能性があります。visibleViewController
そして、 のプロパティをUINavigationViewController
使用しUIViewController
て画面上でを取得できることがわかりました。しかし、そうでない場合はどうすればよいUINavigationViewController
ですか?
どんな助けでも大歓迎です!関連するコードは次のとおりです。
AppDelegate.m
...
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
//I would like to find out which view controller is on the screen here.
UIViewController *vc = [(UINavigationViewController *)self.window.rootViewController visibleViewController];
[vc performSelector:@selector(handleThePushNotification:) withObject:userInfo];
}
...
ViewControllerA.m
- (void)handleThePushNotification:(NSDictionary *)userInfo{
//set some badge view here
}