用户在ViewBased应用程序中启动UILocalNotification时打开特定视图控制器

时间:2012-06-26 07:30:21

标签: iphone objective-c uilocalnotification

我正在使用UILocalNotification.Here当我启动通知时,我需要在应用程序中使用特定视图。但我尝试过以下编码。

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

    // Override point for customization after application launch.
     [[UIApplication sharedApplication]setStatusBarHidden:NO];

    SplashView *mySplash = [[SplashView alloc] initWithImage:
                            [UIImage imageNamed:@"Splash.png"]];

    [window insertSubview:mySplash atIndex:1];

    [window makeKeyAndVisible];


    mySplash.delay = 5;
    mySplash.animation = SplashViewAnimationFade;
    [mySplash startSplash];
        [self.window insertSubview:viewController.view atIndex:0];
        [self.window makeKeyAndVisible];
        [mySplash release];

    // Add the view controller's view to the window and display.    [self.window addSubview:viewController.view];

    UILocalNotification *localNotification = [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];

    if (localNotification) 
    {
        NSLog(@"Notification Body: %@",localNotification.alertBody);
        NSLog(@"%@", localNotification.userInfo);
    }
    [[UIApplication sharedApplication] cancelAllLocalNotifications];

    application.applicationIconBadgeNumber = 0;
    return YES;

}





- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {

UIApplicationState state = [application applicationState];
    if (state == UIApplicationStateInactive) {

showItemContrller = [[Showitem alloc] initWithNibName:@"Showitem" bundle:nil];
        [self.window addSubview:showItemContrller.view];
        [self.window bringSubviewToFront:showItemContrller.view];

}

}

但是当我启动通知时,它显示的是前一个视图,它将显示为showItemControllerView。

感谢你

1 个答案:

答案 0 :(得分:1)

 //comment this line.... 

//[self.window insertSubview:viewController.view atIndex:0];