ios - Launching a specific View Controller when a notification is tapped -
i wish present particular view controller when user taps on view controller. know there many questions same thing have been posted before , there have been many answers none of seems working me. here code in 'didreceiveremotenotification' method in 'appdelegate'
if(application.applicationstate == uiapplicationstateinactive) { nslog(@"inactive"); //show view content of push if(userinfo) { nslog(@"in inactive payload"); // create pointer c object nsstring *cid = [userinfo objectforkey:@"c"]; nslog(cid); pfobject *targetc = [pfobject objectwithoutdatawithclassname:@"c" objectid:cid]; // fetch c object [targetc fetchinbackgroundwithblock:^(pfobject *object, nserror *error) { c *c = [[c alloc] initwithpfobject:object]; // show c view controller if (!error) { nslog(c.title); cdetailsviewcontroller *viewcontroller = [[cdetailsviewcontroller alloc] initwithc:c]; //[self.navigationcontroller pushviewcontroller:viewcontroller animated:yes]; [self.navigationcontroller presentviewcontroller:viewcontroller animated:yes completion:nil]; } }]; } handler(uibackgroundfetchresultnewdata);
i getting exact data have sent in push can see log prints get. problem view controller trying present/push never seen when notification tapped. workaround this? thing i'm doing wrong? highly appreciated.
if app in background, method "application:didreceiveremotenotification:" never called.
you need add this, in method: "application:didfinishlaunchingwithoptions:"
// @ end of method force call didnotification: // handle notifications. if ([launchoptions objectforkey:uiapplicationlaunchoptionsremotenotificationkey]!=nil) { nsdictionary * apush =[launchoptions objectforkey:uiapplicationlaunchoptionsremotenotificationkey]; [self application:application didreceiveremotenotification:apush]; } return yes; }
if app started due user tap notification, in launchoptions dict, notification payload attached.
Comments
Post a Comment