多个UILocalNotifications

时间:2014-03-02 15:07:41

标签: objective-c json uilocalnotification

我正在尝试创建多个UILocalNotifications。我能够一次创建1个通知,但是当我想要同时创建多个通知以及每个通知具有不同的开火日期时等等。现在,您确定,这可以很容易,但问题是通知编号不一致。我可以有4个,然后另一个将有6或7个需要同时创建的通知。所以更像是一个动态列表。我正在使用JSON来获取每个的UTC时间,这就是我用它来解雇它们但我可以将多个UTC日期添加到JSON的UILocalNotification中。这有道理吗?让我知道,我可以尝试更好地解释。对此有什么办法吗?

这是我使用的代码:

   UILocalNotification* localNotification = [[UILocalNotification alloc] init];
localNotification.fireDate = notificationNSDate;
localNotification.accessibilityLabel = [NSString stringWithFormat:@"%@",newsArticleTitle];
localNotification.alertAction = @"open";
localNotification.soundName = UILocalNotificationDefaultSoundName;
localNotification.timeZone = [NSTimeZone systemTimeZone];
localNotification.applicationIconBadgeNumber = [[UIApplication sharedApplication] applicationIconBadgeNumber] + 1;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];

notificationNSDate,是UTC日期值。这是我从JSON转换它的方式:

        dicToString = [NSString stringWithFormat:@"%@",newsArticleTwo];
        notificationTimeString =  dicToString;
        notificationArrat = [notificationTimeString componentsSeparatedByString:@"T"];
        mainNotificationCalendarDate = [notificationArrat objectAtIndex:0];
        mainNotificationTimeString = [notificationArrat objectAtIndex:1];
        timeArray = [mainNotificationTimeString componentsSeparatedByString:@"-"];
        mainNotificationTime = [timeArray objectAtIndex:0];
        timeArrayCorrected = [mainNotificationTime componentsSeparatedByString:@"Z"];
        mainNotificationTimeCorrected = [timeArrayCorrected objectAtIndex:0];
        fullDate = [NSString stringWithFormat:@"%@ %@",mainNotificationCalendarDate,mainNotificationTimeCorrected];
        dateString = fullDate;
        dateFormatter = [[NSDateFormatter alloc] init];
        [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
        dateFromString = [[NSDate alloc] init];
        dateFromString = [dateFormatter dateFromString:dateString];
        notificationNSDate = [dateFromString dateByAddingTimeInterval:-60*240];

newsArticleTwo :是我从另一个viewController传递的NSDictionary:

 svc.newsArticleTwo = [newsArticle objectForKey:@"UTCDateTime"];

希望这有帮助。

0 个答案:

没有答案