Search code examples
iphoneiosxcodeuilocalnotificationpushviewcontroller

iOS Push a specific view when notification arrives


- (void)application:(UIApplication *)app didReceiveLocalNotification:(UILocalNotification *)notif {
    // Handle the notificaton when the app is running

    NSLog(@"Recieved Notification %@",notif);

    NSLog(@"local notifications count = %d", [[[UIApplication sharedApplication] scheduledLocalNotifications] count]);


    CFBundleRef mainBundle = CFBundleGetMainBundle();
    CFURLRef soundFileURLRef;
    soundFileURLRef =CFBundleCopyResourceURL(mainBundle, (CFStringRef) @"everything9", CFSTR ("mp3"), NULL);
    UInt32 soundID;
    AudioServicesCreateSystemSoundID(soundFileURLRef, &soundID);
    AudioServicesPlaySystemSound(soundID);



    [[NSNotificationCenter defaultCenter] postNotificationName:@"RELOAD_DATA"object:nil];

}

What can I implement here to push a specific view when the application arrives (when the user slides the app icon when the iPhone is locked, for example)... I'm trying [self.navigationController pushViewController:CompletedViewController animated:YES]; and I get some errors... Is there a specific way I should do it? Maybe in didFinishLaunchingWithOptions?


Solution

  • maybe you should call this

    [_window.rootViewController pushViewController:CompletedViewController animated:YES];

    The code above doesn't work now. You should try using this instead.

     //We take the rootViewController first which is expected to be a UINavigationController in your case
     UINavigationController *naviController = _window.rootViewController;  
     //We then call the push view controller code    
     [naviController pushViewController:CompletedViewController animated:YES];
    

    this is how you push to your current navigation controller from the AppDelegate if you are using storyboards. Specially if your starting point on the story board is a navigation controller.