ios - Navigate to particular view controller when user tap the notification IOS7 -


hi have added push notification in application , want view particular viewcontrollers when user tap notification. in app delegate m file i'm trying register device token server , server i'm using php script device token server , i'm sending notification.

the problem here i'm trying view particular view controller when user taps on notification not working have tried many different methods nothing had worked.

here i'm view popup send notification app when user trying install application first time.

  - (bool)application:(uiapplication *)application didfinishlaunchingwithoptions:(nsdictionary *)launchoptions  {            [[uiapplication sharedapplication] registerforremotenotificationtypes:(uiremotenotificationtypealert | uiremotenotificationtypebadge | uiremotenotificationtypenone)];             return yes;  }   - (void) clearnotifications {         [[uiapplication sharedapplication] setapplicationiconbadgenumber: 0];         [[uiapplication sharedapplication] cancelalllocalnotifications];  } 

here i'm storing device token server.

-(void)application:(uiapplication *)application didregisterforremotenotificationswithdevicetoken:(nsdata *)devicetoken  {      const char* data = [devicetoken bytes];     nsmutablestring * token = [nsmutablestring string];     (int = 0; < [devicetoken length]; i++) {       [token appendformat:@"%02.2hhx", data[i]];  }        nsstring *urlstring = [nsstring stringwithformat:@"url?token=%@",token];       nsurl *url = [[nsurl alloc] initwithstring:urlstring];      nslog(@"token %@",urlstring);        nsurlrequest *urlrequest = [nsurlrequest requestwithurl:url];      nslog(@"request %@ ",urlrequest);      nsdata *urldata;      nsurlresponse *response;      urldata = [nsurlconnection sendsynchronousrequest:urlrequest returningresponse:&response error:nil];          nslog(@"data %@",urldata);      [self clearnotifications];      //  nslog(@"token ",sendusertoken);      } 

here i'm trying view particular method when user tap notification.

   -(void)application:(uiapplication *)application didreceiveremotenotification:(nsdictionary *)userinfo{            updatepoliticalviewcontroller *ringingvc = [self.window.rootviewcontroller.storyboard instantiateviewcontrollerwithidentifier:@"updatepoliticalviewcontroller"];            [self.window.rootviewcontroller presentviewcontroller:ringingvc animated:yes completion:null];        } 

my particular view controller name updatepoliticalviewcontroller navigation view controller please tell me in above code i'm doing wrong how resolve issue.

thanks

when app in foreground state call

application:didreceiveremotenotification:

but if it's not , app launched, example, swiping alert in notification center

application:didfinishlaunchingwithoptions:

is called key. way call

application:didreceiveremotenotification:

from

application:didfinishlaunchingwithoptions:

i believe should help

- (bool)application:(uiapplication *)application didfinishlaunchingwithoptions:(nsdictionary *)launchoptions {     if (launchoptions[uiapplicationlaunchoptionsremotenotificationkey]) {         [self application:application didreceiveremotenotification:launchoptions[uiapplicationlaunchoptionsremotenotificationkey]];     }     // code...     return yes; } 

// extended

try storyboard that:

// make sure name match uistoryboard *mainstoryboard = [uistoryboard storyboardwithname:@"mainstoryboard" bundle:nil];  

create object mainstoryboard:

updatepoliticalviewcontroller *ringingvc = [mainstoryboard instantiateviewcontrollerwithidentifier:@"updatepoliticalviewcontroller"]; 

and try set new root view controller

[self.window setrootviewcontroller: ringingvc]; 

Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -