Push view from push notification

I receive my notifications successfully for iOS 5. I want users to be able to send a specific view when they scroll or push a push notification in the notification center.

View controller (view) I want the user to go against just starting my application - this is the "groceryStoreViewController". I read that this is done in didFinishLaunchingWithOptions or didReceiveRemoteNotification, but I'm not sure.

If anyone knows how to do this, I would really appreciate it, because it really was a struggle.

thank

EDIT

So the problem is that I want the definition manager to be open when the user deletes the notification, but I also want the UITabBar to stay. I could not do this, and this is due to the fact that I am showing a subview, I believe. Please let me know what you think and thank you.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    

self.tabBarItem = [[[UITabBarItem alloc] init] autorelease];

 exploreViewController *view1 = [[exploreViewController alloc] initWithNibName:@"exploreViewController" bundle:nil];
view1.title= @"Explore";

Upcoming *view2 = [[Upcoming alloc] initWithNibName:@"Upcoming" bundle:nil];
view2.title = @"Upcoming";

TipsViewController *view3 = [[TipsViewController alloc] initWithNibName:@"TipsView" bundle:nil];
view3.title = @"Tips";

UINavigationController *nav1 = [[UINavigationController alloc] initWithRootViewController:view1];
UINavigationController *nav2 = [[UINavigationController alloc] initWithRootViewController:view2];
UINavigationController *nav3 = [[UINavigationController alloc] initWithRootViewController:view3];

[view1 release];
[view2 release];
[view3 release];

self.tabBarController = [[[UITabBarController alloc] init] autorelease];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:nav1,nav2,nav3,nil];
self.tabBarItem = [[[UITabBarItem alloc] init] autorelease];

[nav1 release];
[nav2 release];
[nav3 release];


if (launchOptions != nil)
{  
NSDictionary *remoteNotif = [launchOptions objectForKey: UIApplicationLaunchOptionsRemoteNotificationKey];
NSLog(@"Launched from push notification");
//Accept push notification when app is not open
if (remoteNotif) {      

 NSDictionary *alertBody = [remoteNotif objectForKey:@"loc-key"];

 self.window.rootViewController = nav2;  //this is what I want displayed when tapped but also maintain tab bar controller
    [window addSubview:tabBarController.view];
    [window makeKeyAndVisible];

  }
}
else {

    //Go here if just loading up normally without push
    [window addSubview:tabBarController.view];
    [window makeKeyAndVisible];

}
  return YES;

}
+2
source share
1 answer

This is done in the method didFinishLaunchingWithOptions:. You can check if the application is running due to a notification and set the appropriate viewController to display.

Sort of:

-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    // other stuff

    if (launchOptions != nil) {
        NSLog(@"Launched from push notification");
        NSDictionary *notification = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
        // Do something with the notification dictionary
        self.myViewController = [LaunchFromNotificationViewController alloc] init];
    } else {
        self.myViewController = [OrdinaryLaunchViewController alloc] init];
    }

    self.window.rootViewController = self.myViewController;
    [self.windows makeKeyAndVisible];
    return YES;
}
+3
source

All Articles