删除特定notification
我的app已经开启了remote notification, 并且当app处于后台状态的时候调用[[UNUserNotificationCenter currentNotificationCenter] removeDeliveredNotificationsWithIdentifiers:@[request.identifier]]是可以正常的删除对应的推送通知.但是当我把APP杀死之后,调用该方法也无法删除对应的推送,只有当进入app的时候才会删除对应的推送.请问有什么解决办法吗?
NSString *key = userInfo[@"aps"][@"extendInfo"][@"name"];
NSString *type = userInfo[@"aps"][@"alert"][@"title"];
if ([type isEqualToString:@"deleteChannel"]) {
[[UNUserNotificationCenter currentNotificationCenter] getDeliveredNotificationsWithCompletionHandler:^(NSArray<UNNotification *> * _Nonnull notifications) {
if (notifications.count == 0) {
completionHandler(UIBackgroundFetchResultNewData);
return;
}
else {
for (UNNotification *notice in notifications) {
UNNotificationRequest *request = notice.request;
UNNotificationContent *content = request.content;
NSDictionary *userInfo1 = content.userInfo;
NSString *title = userInfo1[@"aps"][@"alert"][@"body"];
if ([title isEqualToString: key]) {
[[UNUserNotificationCenter currentNotificationCenter] removeDeliveredNotificationsWithIdentifiers:@[request.identifier]];
break;
}
}
completionHandler(UIBackgroundFetchResultNewData);
}
}];
}
else {
switch (application.applicationState) {
case UIApplicationStateActive:
case UIApplicationStateInactive:
case UIApplicationStateBackground: {
completionHandler(UIBackgroundFetchResultNewData);
break;
}
default:
break;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你好 你这个代码是写在 didReceiveRemoteNotification里面吗? 我怎么写过后 不执行呢?