0

I would set the opening off us specific view by opening a push notification sent from parse.Using IOS 8. How can i do that?? I used this code:

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
UINavigationController *navController = (UINavigationController *)self.window.rootViewController;
NotificationViewController *notificationViewController = [[NotificationViewController alloc] init];
[navController.visibleViewController.navigationController pushViewController:notificationViewController animated:YES];    

}

Swifty Srl
  • 33
  • 5

1 Answers1

0

I use this code

- (UIViewController*)topViewController {
    return [self topViewControllerWithRootViewController:[UIApplication sharedApplication].keyWindow.rootViewController];
}


- (UIViewController*)topViewControllerWithRootViewController:(UIViewController*)rootViewController {

    if ([rootViewController isKindOfClass:[UITabBarController class]]) {
        UITabBarController* tabBarController = (UITabBarController*)rootViewController;
        return [self topViewControllerWithRootViewController:tabBarController.selectedViewController];
    } else if ([rootViewController isKindOfClass:[UINavigationController class]]) {
        UINavigationController* navigationController = (UINavigationController*)rootViewController;
        return [self topViewControllerWithRootViewController:navigationController.visibleViewController];
    } else if (rootViewController.presentedViewController) {
        UIViewController* presentedViewController = rootViewController.presentedViewController;
        return [self topViewControllerWithRootViewController:presentedViewController];
    } else {
        return rootViewController;
    }
}

Called this way:

- (void) doSomething {
    UIViewController *topViewController = [self topViewController];
    NotificationViewController *notificationViewController = [[NotificationViewController alloc] init];
    [topViewController.navigationController pushViewController:notificationViewController animated:YES];
}

Don't forget to put this code on your application:didFinishLaunchingWithOptions: (when a user touches a notification with the app closed)

    NSDictionary *remoteNotification = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
if (!remoteNotification) {
    UILocalNotification *notification = [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
    if (notification) {
        [self doSomething];
    }
} else {
    [self doSomething];
}
Politta
  • 400
  • 4
  • 10
  • I did this but it stil doesn't work;I've edited this code: - (void) doSomething { UIViewController *topViewController = [self topViewController]; Mappa *notificationViewController = [[Mappa alloc] init]; [topViewController.navigationController pushViewController:notificationViewController animated:YES]; } – Swifty Srl Jul 24 '15 at 15:14
  • What exactly isn't working? You called doSomething inside application:didReceiveRemoteNotification: right? – Politta Jul 24 '15 at 17:32
  • I called doSomething in didReciveRemoteNotification but it doesn't work.When i open the app from push notification it continue to open in mainView. In doSomething is it correct to have replaced the myViewController with notificationViewController? – Swifty Srl Jul 27 '15 at 08:25
  • If your app is closed, you need to use the last code in my response. – Politta Jul 28 '15 at 14:31