ios - Update badge icon when app is in background/suspended mode -
i want update application badge icon when notification received. works fine when app running (active mode),but having trouble when trying set when app in suspended/background mode. want achieve same without using 'badge' field in apns dictionary.
here doing,
-(void) incrementonebadge{ nsinteger numberofbadges = [uiapplication sharedapplication].applicationiconbadgenumber; numberofbadges +=1; [[uiapplication sharedapplication] setapplicationiconbadgenumber:numberofbadges]; } -(void) decrementonebadge{ nsinteger numberofbadges = [uiapplication sharedapplication].applicationiconbadgenumber; numberofbadges -=1; [[uiapplication sharedapplication] setapplicationiconbadgenumber:numberofbadges]; } -(void) application:(uiapplication *)application didreceiveremotenotification:(nsdictionary *)userinfo fetchcompletionhandler:(void (^)(uibackgroundfetchresult))completionhandler { uiapplicationstate state = [application applicationstate]; if (state == uiapplicationstateactive) { } else { // push notification received in background [self incrementonebadge]; } [self handlepushnotificationsforstate:application withdictionary:userinfo]; }
Comments
Post a Comment