ios - Clear Banner Notification When Tapped -
i have noticed when select push notification app notification center, notification no longer appears in list of notifications. however, when receive notification , tap banner right away, app opens should, when pull down view notification center, notification still there. have following push handling code in delegate:
- (void)application:(uiapplication *)application didreceiveremotenotification:(nsdictionary *)userinfo { [[uiapplication sharedapplication] cancelalllocalnotifications]; //presenting view controllers... } - (bool)application:(uiapplication *)application didfinishlaunchingwithoptions:(nsdictionary *)launchoptions { // override point customization after application launch. // extract notification data nsdictionary *notificationpayload = launchoptions[uiapplicationlaunchoptionsremotenotificationkey]; if(notificationpayload) { [[uiapplication sharedapplication] cancelalllocalnotifications]; } return yes; } - (void)applicationwillenterforeground:(uiapplication *)application { // called part of transition background inactive state; here can undo many of changes made on entering background. application.applicationiconbadgenumber = 0; [[uiapplication sharedapplication] cancelalllocalnotifications]; } -(void)application:(uiapplication *)application didreceivelocalnotification:(uilocalnotification *)notification { // when tap on of notification delegate method call... [[uiapplication sharedapplication] setapplicationiconbadgenumber:0]; [[uiapplication sharedapplication] cancellocalnotification:notification]; }
you have use following remove notifications
- (void)applicationwillenterforeground:(uiapplication *)application { // called part of transition background active state; here can undo many of changes made on entering background. [self clearnotifications]; } - (void)applicationdidbecomeactive:(uiapplication *)application { // restart tasks paused (or not yet started) while application inactive. if application in background, optionally refresh user interface. [self clearnotifications]; } - (void)clearnotifications { [[uiapplication sharedapplication] setapplicationiconbadgenumber: 1]; [[uiapplication sharedapplication] setapplicationiconbadgenumber: 0]; [[uiapplication sharedapplication] cancelalllocalnotifications]; }
Comments
Post a Comment