Application didreceiveRemoteNotification and jumping to a specific view

后端 未结 1 1478
梦毁少年i
梦毁少年i 2021-01-24 09:22

I have been trying everything to work this out. I get a notification when the app is closed with 2 custom items, a type and an id. The type is supposed to tell me which view to

相关标签:
1条回答
  • 2021-01-24 09:33

    Normally for this requirement I would do this..

    1. Use NSNotificationCenter and post a notification from didReceiveRemoteNotification.

      [[NSNotificationCenter defaultCenter] postNotificationName:@"notificationReceived"     object:self userInfo:userInfo];
      
    2. Subscribe to it from the VC from where you can open your details view to show the message.

      [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationReceived:) name:@"notificationReceived" object:nil];
      
    3. If you are instantiating the VC yourself and not using segue. you can do this..

      UIStoryboard* storyBoard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
      detailVC = [storyBoard instantiateViewControllerWithIdentifier:@"detailVC"];
      detailVC.delegate = self;
      
      detailVC.userInfo = @"YOUR DATA";
      [self presentViewController:detailVC animated:YES completion:nil];
      
    4. To return you can do this in your detail VC..

      [self dismissViewControllerAnimated:YES completion:nil];
      
    0 讨论(0)
提交回复
热议问题