UIApplication scheduledLocalNotifications对于过去的非重复通知为空 [英] UIApplication scheduledLocalNotifications is empty for past non-repeating notifications

查看:523
本文介绍了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对于过去的非重复通知为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆