How to clear a single notification from a list of

2019-02-15 12:03发布

问题:

Once i click a notification, all the notifications are cleared.In ios, is there any option to clear a single notification after tapping on it? i have received 4 notifications. now i need the clicked notification alone to get cleared and retain the other ones.Can anyone help me on this?

- (void) clearNotifications {
    [[UIApplication sharedApplication] setApplicationIconBadgeNumber: 0];
    [[UIApplication sharedApplication] cancelAllLocalNotifications];
}

- (void)application:(UIApplication*)application didReceiveRemoteNotification:(NSDictionary*)userInfo
{    
    NSLog(@"Received notification: %@", userInfo);
    [self clearNotifications];
}

回答1:

-(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{

// when you tap on any of notification this delegate method will call... 

    [[UIApplication sharedApplication] cancelLocalNotification:notification];

}