如何清除iOS中的通知

Bac*_*tnz 1 objective-c push-notification ios

如果用户将警报样式设置为横幅.他们可以收到超过1个通知,而不会提示他们清除它.然后他们去使用他们的手机,他们说3存储.如果点击最新的那个&它打开应用程序,我想只清除这一个通知,我也需要去badgeCount--;

如何使用下面的代码实现它?(目前它已经开始清理所有我不想要的东西......)我也注意到有时它会更新徽章编号.但是,如果我切换回iOS主屏幕并下拉通知菜单,它仍然存在!

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
    if([[userInfo valueForKey:@"aps"] valueForKey:@"alert"] != nil) {
        NSString *message = [[userInfo valueForKey:@"aps"] valueForKey:@"alert"];
        if(message != nil) {
            UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Usage Alert"
            message:message  delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok", nil];
            [alertView show];
            [[UIApplication sharedApplication] setApplicationIconBadgeNumber: 0];
            [[UIApplication sharedApplication] cancelAllLocalNotifications];

        }
    }
}
Run Code Online (Sandbox Code Playgroud)

Ani*_*ese 5

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


 UIApplication *app = [UIApplication sharedApplication];
 NSInteger badgeNumber = [app applicationIconBadgeNumber];// Take the current badge number
 badgeNumber--;    // decrement by one 
 [app setApplicationIconBadgeNumber:badgeNumber];  // set ne badge number
 [app cancelLocalNotification:notification];    // cancel the received notification. It will clear the notification from banner alos
}
Run Code Online (Sandbox Code Playgroud)