如何永久删除n UILocalNotification?

时间:2013-10-25 06:04:56

标签: ios iphone objective-c

我尝试过NSLog(@"The notifications is \n %@",notification);

  

并且日志消息是:2013-10-18 12:23:36.010剩余[2433:207]通知是{fire date =(null),时区= Asia / Kolkata(IST)偏移19800,重复间隔= 0,重复计数= UILocalNotificationInfiniteRepeatCount,下次开火日期= 2013年10月18日星期五下午12:23:36印度标准时间}

3 个答案:

答案 0 :(得分:0)

删除特定通知

[[UIApplication sharedApplication] cancelLocalNotification: notification];

取消所有通知

[[UIApplication sharedApplication] cancelAllLocalNotifications];

答案 1 :(得分:0)

您必须删除特定的预定通知,您必须使用以下方法。

[[UIApplication sharedApplication] cancelLocalNotification: notification];

答案 2 :(得分:0)

如果返回null,则不返回通知。所以试试这个

方法一:

-(void) scheduleNotificationForDate:(NSDate *)date AlertBody:(NSString *)alertBody ActionButtonTitle:(NSString *)actionButtonTitle NotificationID:(NSString *)notificationID{

    UILocalNotification *localNotification = [[UILocalNotification alloc] init];
    localNotification.fireDate = date;
    localNotification.timeZone = [NSTimeZone localTimeZone];
    localNotification.alertBody = alertBody;
    localNotification.alertAction = actionButtonTitle;
    localNotification.soundName = @"yourSound.wav";

    NSDictionary *infoDict = [NSDictionary dictionaryWithObject:notificationID forKey:notificationID];
    localNotification.userInfo = infoDict;

    [[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
}

方法2:

设置通知后,唯一的编辑方式是取消旧通知并重新创建另一个通知,这样您就可以这样做,搜索现有通知并取消通知。

`for(UILocalNotification *aNotif in [[UIApplication sharedApplication] scheduledLocalNotifications]) 
{
        if([[aNotif.userInfo objectForKey:@"id"] isEqualToString:nId])
 {
            [[UIApplication sharedApplication]cancelLocalNotification:aNotif];
        }
    }`