【问题标题】:How to delete n UILocalNotification permanently?如何永久删除 n UILocalNotification?
【发布时间】:2013-10-25 06:04:56
【问题描述】:

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

日志消息是:2013-10-18 12:23:36.010 Remainder[2433:207] 通知是 {fire date = (null), time zone = Asia/Kolkata (IST) offset 19800, repeat interval = 0,重复计数 = UILocalNotificationInfiniteRepeatCount,下一次触发日期 = 印度标准时间 2013 年 10 月 18 日星期五下午 12:23:36}

【问题讨论】:

    标签: ios iphone objective-c


    【解决方案1】:

    如果返回 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];
    }
    

    方法二:

    一旦你设置了通知,编辑它的唯一方法就是取消旧的并重新创建另一个,所以你可以这样做,搜索你现有的并取消它。

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

    【讨论】:

    • 欢迎您有美好的一天 :)
    【解决方案2】:

    用于删除特定通知

    [[UIApplication sharedApplication] cancelLocalNotification: notification];
    

    并取消所有通知

    [[UIApplication sharedApplication] cancelAllLocalNotifications];
    

    【讨论】:

      【解决方案3】:

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

      [[UIApplication sharedApplication] cancelLocalNotification: notification];

      【讨论】:

        猜你喜欢
        • 2016-10-31
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-10-28
        • 2017-10-21
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多