objective c - ios push notifications to a specific view controller -


my app receives remote push notifications , upon receiving them, take specific view controller(pretty time). have seen code (on didreceiveremotenotification). using storyboard apps.

    uiviewcontroller *vc = self.window.rootviewcontroller;     pushviewcontroller *pvc = [vc.storyboard instantiateviewcontrollerwithidentifier:@"someid"];     [vc presentviewcontroller:pvc animated:yes completion:nil]; 

this seems straightforward enough. have impact on memory allocation, looks every time push notification arrives, instantiating new view controller. best practice?

you can try like:

    pushviewcontroller *vc = [self.storyboard instantiateviewcontrollerwithidentifier:@"someid"];     [[uiapplication sharedapplication].keywindow.rootviewcontroller presentviewcontroller:vc animated:yes completion:nil]; 

you dont need allocate uiviewcontroller rootview everytime unless want have uiviewcontroller present pushvc.

if doing in app delegate, storyboard reference by:

  uistoryboard *test=[uistoryboard storyboardwithname:@"name" bundle:nil]; 

and call

  [test instantiateviewcontrollerwithidentifier..... 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -