嗨,大家好我的应用程序有问题,我想添加一些基本的LocalNotifications,每周重复一次。我想在名为" scheduleLocalNotificationForItem:"的方法中执行此操作,该方法在按下doneBarButtonItem时调用。到目前为止,这一切似乎都有效,因为当我记录所有预定的通知时,每个预定的通知都会显示出来。但是当我使用该应用程序时,预定的通知会被触发并显示,但是有一些额外的通知,我自己也没有这样做,我无法确定它们的来源,这也是出现的。
所以这是我的代码:
- (int)scheduleNotifitactionsForItem:(AlarmItem *)item
{
NSArray *reorderdRepeat = [NSArray arrayWithArray:[self transformArray:item.repeat]];
int missedDays = 0;
int scheduledAlarms = 0;
for (int i = 0; i < item.repeat.count; i++) {
if ([[reorderdRepeat objectAtIndex:i] boolValue] == true) {//Problem determinating true values at end of array
NSInteger integerOfDay = i + 1;//reorderRepeat should contain seven items, icrement i bevore adding it to integerOfDay
NSDate *lastAlarmTime = [self getFireDateForDayOfWeek:integerOfDay withTime:item.time];
NSArray *allAlramTimesForDay = [self getFireDatesForTime:lastAlarmTime andCycle:item.cycles];
for (int i = 0; i < allAlramTimesForDay.count; i++) {
NSDate *alarmTime = [allAlramTimesForDay objectAtIndex:i];
UIApplication *application = [UIApplication sharedApplication];
UILocalNotification *notification = [UILocalNotification new];
NSDictionary *userInfo = @{@"index":[NSString stringWithFormat:@"%d",item.notification]};
notification.repeatInterval = NSCalendarUnitWeekday;
notification.alertBody = item.title;
notification.userInfo = userInfo;
notification.fireDate = alarmTime;
notification.soundName = item.sound;
[application scheduleLocalNotification:notification];
scheduledAlarms += 1;
}
} else {
missedDays += 1;
}
}
return scheduledAlarms;
}
感谢帮助;)
答案 0 :(得分:1)
您的 repeatInterval 应为NSCalendarUnitWeekOfYear
(或旧NSWeekCalendarUnit
)。 NSCalendarUnitWeekday
(NSWeekdayCalendarUnit
)每天都会重复。