本地通知和打开特定屏幕

时间:2013-04-17 12:13:48

标签: model-view-controller uiviewcontroller uinavigationcontroller uilocalnotification

当我收到本地通知时,我想打开我的特定屏幕。 目前在我的应用程序中我使用了导航控制器以及模型视图控制器,因此在导航控制器时,应用程序正在切换任何视图但是当模型控制器退出时。它没有打开屏幕。 Plz建议任何解决方案?

1 个答案:

答案 0 :(得分:1)

There are two way to launch app when notification comes.

1- app在后台运行。然后打开特定的屏幕      - (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification     {

   // write this line  
   [[NSNotificationCenter defaultCenter] postNotificationName:@"reloadData" object:self];


}

in which controller class you are create notification.
- (void)viewDidLoad
 {
    [super viewDidLoad];

      [[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(reloadTable)
                                             name:@"reloadData"
                                           object:nil];
   }

- (void)reloadTable
  {
     //  create object of that controller which your want to open.

    UIStoryboard *sb = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
     AddToDoViewController *cvc = (AddToDoViewController *)[sb    instantiateViewControllerWithIdentifier:@"AddToDo"];

    [self presentModalViewController:cvc animated:YES];

}