1

When Push notification arrives, when app is in kill state , I need to navigate to specific view controller from appdelegate when the app is launched by tapping push notification?

//helper method to handle push notification

- (void)handleNotification:(NSDictionary *)userInfo {
    NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults];
    NSString * token = [defaults objectForKey:@"token"];

    UINavigationController *navigationController = (UINavigationController *) self.window.rootViewController;
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    if (token!=NULL) {
        // Show the dashboard
        [navigationController pushViewController:[storyboard instantiateViewControllerWithIdentifier:@"listviewcontroller"] animated:NO];
    } else {
        // Login
        [navigationController pushViewController:[storyboard instantiateViewControllerWithIdentifier:@"viewcontroller"] animated:NO];
    }



}

Is this Correct? or do I need to make any changes?

Siba Prasad Hota
  • 4,779
  • 1
  • 20
  • 40
Yogaraj R
  • 73
  • 1
  • 6
  • I think you need to write code in `ApplicationDidfinishLaunching` to get the notification details when your app is killed. – Siba Prasad Hota Feb 22 '16 at 05:11
  • Possible duplicate of [Open Specific View when Opening App from Notification](http://stackoverflow.com/questions/15501500/open-specific-view-when-opening-app-from-notification) – Ronak Chaniyara Feb 22 '16 at 05:15
  • @SibaPrasadHota:i have called this method from application did finish launching – Yogaraj R Feb 22 '16 at 05:19

1 Answers1

0

Write your logic in didFinishLaunchingWithOptions, where you will get the notification data.

You will get the specific key when user tap on any Notification:

launchOptions?["UIApplicationLaunchOptionsRemoteNotificationKey"]

If you get this value then you insert the logic of Navigating to specific UIViewController else nothing.

Sohil R. Memon
  • 9,404
  • 1
  • 31
  • 57