无法多次添加 UILocalNotification

Not able to add UILocalNotification multiple time

我正在尝试将 UILocalNotification 添加到具有不同日期(例如一周)的循环中。当我添加开火日期时没有改变。下面是我的代码,请帮我解决这个问题。提前致谢。

NSDate *now = [NSDate date];
BOOL isTimer = NO;
for(i=1;i<8;i++){    
 NSDate *date = [now dateByAddingTimeInterval:60*60*24*i];    
    UILocalNotification *localNotification = [[UILocalNotification alloc] init]; //Create the localNotification object

    [localNotification setTimeZone:[NSTimeZone defaultTimeZone]];
    NSLog(@"user date time before firing %@",date);
    [localNotification setFireDate:(isTimer?[NSDate getDateFromString:[NSDate getEndDateTime:timeInt]]:date)];
    NSLog(@"notification fire date %@",localNotification.fireDate);

    //Set the date when the alert will be launched using the date adding the time the user selected on the timer
    [localNotification setAlertAction:@"Open"]; //The button's text that launches the application and is shown in the alert
    [localNotification setAlertBody:titleHeader]; //Set the message in the notification from the textField's text
    localNotification.soundName = UILocalNotificationDefaultSoundName;
    [localNotification setHasAction: YES]; //Set that pushing the button will launch the application
    [localNotification setUserInfo:[NSDictionary dictionaryWithKeysAndObjects:@"title",titleHeader,@"url",link, nil]];
    [[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
    localNotification = nil;
}

下面是日志

user date time before firing 2015-06-10 05:22:00 +0000
notification fire date 2015-06-10 16:11:14 +0000

user date time before firing 2015-06-11 05:22:00 +0000
notification fire date 2015-06-10 16:11:19 +0000

user date time before firing 2015-06-12 05:22:00 +0000
notification fire date 2015-06-10 16:12:34 +0000

user date time before firing 2015-06-13 05:22:00 +0000
notification fire date 2015-06-10 16:12:38 +0000

user date time before firing 2015-06-14 05:22:00 +0000
notification fire date 2015-06-10 16:12:39 +0000

user date time before firing 2015-06-15 05:22:00 +0000
notification fire date 2015-06-10 16:12:39 +0000

user date time before firing 2015-06-16 05:22:00 +0000
notification fire date 2015-06-10 16:12:39 +0000

问题是 isTimer 是真的,所以你一遍又一遍地使用同一个日期;您的 date 变量每次循环都不同,但从未使用过。