本地通知 - 每天的特定消息

时间:2015-10-16 12:07:00

标签: ios objective-c xml uilocalnotification

我对本地通知有点问题。我正在从XML(datum - date和jmeno - name)加载数据,我需要为notification.alertBody设置特定日期的不同消息(例如,当时为16.10,从XML加载的日期也是16.10,消息是&# 34; Feast有Havel"当时是17.10,XML的日期也是17.10,消息是"盛宴有Hedwig,"等等。)如果申请被关闭。但是我总是收到应用程序上次运行日期的notification.alertBody。

我的代码是本地通知:

NSDate *today = [NSDate date];
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"dd.MM."];
NSString *dateString = [dateFormat stringFromDate:today];

UILocalNotification *notification = [[UILocalNotification alloc] init];

NSCalendar *calendar = [NSCalendar currentCalendar];
NSDateComponents *components = [[NSDateComponents alloc] init];
[components setDay: 3];
[components setMonth: 7];
[components setYear: 2012];
[components setHour: 9];
[components setMinute: 54];
[components setSecond: 0];
[calendar setTimeZone: [NSTimeZone defaultTimeZone]];
NSDate *dateToFire = [calendar dateFromComponents:components];

for (i = 0; i < [self.slovoArray count]; i++)
{
     slova = [self.slovoArray objectAtIndex:i];

     if([slova.datum isEqual:dateString])
     {
     notification.alertBody = [NSString stringWithFormat:@"Dnes je %@, státní svátek %@", slova.datum, slova.jmeno];
     }
         [notification  setFireDate: dateToFire];
         [notification setTimeZone: [NSTimeZone localTimeZone]];
         [notification setRepeatInterval: NSCalendarUnitDay];
         notification.soundName = UILocalNotificationDefaultSoundName;
         notification.applicationIconBadgeNumber = 0;
         [[UIApplication sharedApplication] scheduleLocalNotification:notification];
         [alertNotification setHidden:NO];
         }
 }

0 个答案:

没有答案