iOS从托盘中删除旧通知并显示新收到的通知



我们正在使用firebase发送push notification,是否可以从通知托盘中删除duplicate notification。在通知 JSON 中,我们正在发送名为uid的参数,如果旧通知中已经提供了相同的uid,这意味着我们需要从通知中心删除旧通知并显示新通知。怎么可能?或者给我一些更好的解决方案来修复它。

-(void)deleteNotificationWithId:(NSString*)Id
{ 
NSString *myIDToCancel = [NSString stringWithFormat:@"%@",Id];
NSString *currSysVer = [[UIDevice currentDevice] systemVersion];
if([currSysVer floatValue] >= 10)
{
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
[center getPendingNotificationRequestsWithCompletionHandler:^(NSArray<UNNotificationRequest *> * _Nonnull requests) {
NSMutableArray *strArrayToDelete = [[NSMutableArray alloc] init];
for (UNNotificationRequest *request in requests){
if([myIDToCancel isEqualToString:[request.content.userInfo objectForKey:@"ID"]])
{
[strArrayToDelete addObject:request.identifier];
}
}
if(strArrayToDelete.count >0)
{
[center removePendingNotificationRequestsWithIdentifiers:strArrayToDelete];
}
}];
}
else
{
NSString *myIDToCancel = Id;
UILocalNotification *notificationToCancel=nil;
for(UILocalNotification *aNotif in [[UIApplication sharedApplication] scheduledLocalNotifications])
{
if([[aNotif.userInfo objectForKey:@"ID"] isEqualToString:myIDToCancel])
{
notificationToCancel=aNotif;
[[UIApplication sharedApplication] cancelLocalNotification:notificationToCancel];
break;
}
}
}
}
}

相关内容

  • 没有找到相关文章

最新更新