update sqlite db from push notification, app is closed and not running in background iOS -
i trying update local sqlite database when notification received , app closed/killed user. works fine when app background or active mode.
reference : reference stack link 1
here code trying:
-(void)application:(uiapplication )application didreceiveremotenotification:(nsdictionary )userinfo fetchcompletionhandler:(nonnull void (^)(uibackgroundfetchresult))completionhandler{ nslog(@"app background :%@",userinfo); if(application.applicationstate == uiapplicationstateinactive) { nslog(@"inactive"); //show view content of push [self backgrouncall:userinfo]; completionhandler(uibackgroundfetchresultnewdata); } else if (application.applicationstate == uiapplicationstatebackground) { nslog(@"background"); //refresh local model [self backgrouncall:userinfo]; completionhandler(uibackgroundfetchresultnewdata); } else { nslog(@"active"); //show in-app banner [self backgrouncall:userinfo]; completionhandler(uibackgroundfetchresultnewdata); } }
question : why not working in application inactive state. there solution issue ?
- (bool)application:(uiapplication )application didfinishlaunchingwithoptions:(nsdictionary )launchoptions { // override point customization after application launch. [[database sharedatabase] createeditablecopyofdatabaseifneeded]; if(launchoptions != nil) { // opened push notification when app closed nsdictionary* userinfo = [launchoptions objectforkey:uiapplicationlaunchoptionsremotenotificationkey]; if (userinfo != nil) { nslog(@"userinfo->%@", [userinfo objectforkey:@"aps"]); [self application:application didreceiveremotenotification:launchoptions[uiapplicationlaunchoptionsremotenotificationkey]]; } } else { } }
-(void)application:(uiapplication )application didreceiveremotenotification:
method gets called if user tap on notification banner if app in background. if app killed need handle tap of banner in
didfinishlaunchwithoptions
method.you can use following code know if tap on banner , app killed.
// push notification handling [uiapplication sharedapplication].applicationiconbadgenumber = 0; nsdictionary *pushdic = [[nsdictionary alloc]init]; pushdic = [launchoptions objectforkey:@"uiapplicationlaunchoptionsremotenotificationkey"]; if (pushdic) { nslog(@"got push when app killed->%@",pushdic); }
Comments
Post a Comment