我在我的项目中使用SWRevealViewController,我想在应用收到通知时打开特定的控制器。我尝试了很多解决方案,但没有任何效果。
如何从我的 AppDelegate 中显示特定的 ViewController?
(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
UIApplicationState appState = UIApplicationStateActive;
if ([application respondsToSelector:@selector(applicationState)]) {
appState = application.applicationState;
}
application.applicationIconBadgeNumber = 0;
if (appState != UIApplicationStateActive) {
SWRevealViewController *navigationController = (SWRevealViewController *)self.window.rootViewController;
UINavigationController *nav = (UINavigationController *)navigationController;
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle: nil];
PushNotificationsVC *controller = (PushNotificationsVC*)[mainStoryboard instantiateViewControllerWithIdentifier: @"PushNotificationsVC"];
[nav pushViewController:controller animated:YES];
} else {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Notification"
message:[NSString stringWithFormat:@"%@",[[userInfo objectForKey:@"aps"] valueForKey:@"alert"]]
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alertView show];
}
}