UILocalNotification 已触发但未安排

UILocalNotification triggered but not scheduled

大家好我的应用程序有问题,我想在其中添加一些基本的 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;
}

感谢帮助 ;)

您的 repeatInterval 应该是 NSCalendarUnitWeekOfYear(或旧的 NSWeekCalendarUnit)。 NSCalendarUnitWeekday (NSWeekdayCalendarUnit) 每天都会重复。