gpt4 book ai didi

ios - 如何在iOS中仅清除通知

转载 作者:行者123 更新时间:2023-12-01 17:32:40 26 4
gpt4 key购买 nike

如果用户将警报样式设置为横幅。他们可以收到多个通知,而不会提示他们清除通知。然后他们去使用电话,并且说了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];

}
}
}

最佳答案

-(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
}

关于ios - 如何在iOS中仅清除通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15079545/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com