UIApplication scheduledLocalNotifications对于过去的非重复通知为空

编程入门 行业动态 更新时间:2024-10-12 08:19:14
本文介绍了UIApplication scheduledLocalNotifications对于过去的非重复通知为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我已尝试过 3do应用,这似乎能够以调度不重复的通知并删除来自通知中心的特定通知。它的工作原理是这样的:当应用程序在后台,他们在通知中心交付,如果你选择这些通知3do将打开,你有选择点击完成,如果你点击完成的具体通知将被删除从通知中心。如果你不点击任何东西,通知将留在通知中心。

I have tried out the 3do app which seems to be able to schedule non-repeating notifications and have specific notifications from notification center deleted. It works as this: when app is in background they are delivered in notification center, if you choose one of these notifications 3do will open and you have the option to tap "done", if you tap "done" that specific notification will be removed from the notification center. If you don't tap anything the notification will be left in notification center.

这是我自己在我自己的应用程序中的问题,我不能了解如何从通知中心删除个别通知。如果通知没有重复间隔,那么UIApplication的 scheduledLocalNotifications 数组将为空,因此我无法取消该特定通知并将其从通知中心删除。但是,如果通知有重复间隔,scheduledLocalNotifications数组将不为空,我可以删除此通知。但是如何处理通知不重复的情况?

This is the problem I am myself having in one of my own applications, I can't understand how to delete an individual notification from the notification center. If the notification does not have a repeat interval then the scheduledLocalNotifications array of UIApplication will be empty so I can't cancel that specific notification and have it removed from the notification center. However if the notification has a repeat interval the scheduledLocalNotifications array will not be empty and I can delete this notification. But how can I deal with the scenario when the notifications are non-repeating?

推荐答案

scheduledLocalNotifications数组显示为空,即使您已设置本地通知。最好的办法是保留单独的本地通知对象。

scheduledLocalNotifications array will show as empty even if you have set local notifications. Best way is to keep individual local notification objects. So that you can easily delete it.

当您设置本地通知时,像这样保存对象

When you set local Notification, save the object like this

[[UIApplication sharedApplication] scheduleLocalNotification:localNotification]; NSString *userDefKey = @"key"; NSData *dataEnc = [NSKeyedArchiver archivedDataWithRootObject:localNotification]; [[NSUserDefaults standardUserDefaults] setObject:dataEnc forKey:userDefKey];

您应该保留金钥

您要删除特定的本地通知

When you want to delete a specific local notification

if([[NSUserDefaults standardUserDefaults] objectForKey:userDefKey]){ NSData *data = [[NSUserDefaults standardUserDefaults] objectForKey:userDefKey]; UILocalNotification *localNotif = [NSKeyedUnarchiver unarchiveObjectWithData:data]; [[UIApplication sharedApplication] cancelLocalNotification:localNotif]; }

更多推荐

UIApplication scheduledLocalNotifications对于过去的非重复通知为空

本文发布于:2023-11-27 10:53:16,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1637776.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:为空   通知   UIApplication   scheduledLocalNotifications

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!