我计划了10个iOS UILocalNotification,但只有6个被解雇

我计划了10个iOS UILocalNotification,但只有6个被解雇,ios,uilocalnotification,Ios,Uilocalnotification,我写了10个UILocalNotification,但只有6个被解雇。这很奇怪。如果我安排5次,只有3次被解雇。有人能帮我一下吗?提前谢谢。以下是处理调度的方法 - (void)scheduleLocalNotifications { // Get the current datetime NSDate *current = [NSDate date]; // Get the intervals float workSessionInterval1 = (isW

我写了10个UILocalNotification,但只有6个被解雇。这很奇怪。如果我安排5次,只有3次被解雇。有人能帮我一下吗?提前谢谢。以下是处理调度的方法

- (void)scheduleLocalNotifications
{
    // Get the current datetime
    NSDate *current = [NSDate date];

    // Get the intervals
    float workSessionInterval1 = (isWorking) ? (float)currentSessionTimer : (float)currentSessionTimer+(float)workingTimeSpan;
    float restSessionInterval1 = (isWorking) ? workSessionInterval1+(float)restTimeSpan : (float)currentSessionTimer;

    float workSessionInterval2 = restSessionInterval1 + (float)workingTimeSpan;
    float restSessionInterval2 = workSessionInterval1 + (float)restTimeSpan;

    float workSessionInterval3 = restSessionInterval2 + (float)workingTimeSpan;
    float restSessionInterval3 = workSessionInterval2 + (float)restTimeSpan;

    float workSessionInterval4 = restSessionInterval3 + (float)workingTimeSpan;
    float restSessionInterval4 = workSessionInterval3 + (float)restTimeSpan;

    float workSessionInterval5 = restSessionInterval4 + (float)workingTimeSpan;
    float restSessionInterval5 = workSessionInterval4 + (float)restTimeSpan;

    // Schedule working session ends notifications
    UILocalNotification *workSessionEndNotif1 = [[UILocalNotification alloc] init];
    workSessionEndNotif1.fireDate = [current dateByAddingTimeInterval:workSessionInterval1];
    workSessionEndNotif1.timeZone = [NSTimeZone defaultTimeZone];
    workSessionEndNotif1.alertBody = @"You working session finishes. Go to have a rest";
    workSessionEndNotif1.alertAction = @"View";
    workSessionEndNotif1.soundName = UILocalNotificationDefaultSoundName;
    workSessionEndNotif1.applicationIconBadgeNumber = 1;
    [[UIApplication sharedApplication] scheduleLocalNotification:workSessionEndNotif1];
    workSessionEndNotif1 = nil;

    UILocalNotification *workSessionEndNotif2 = [[UILocalNotification alloc] init];
    workSessionEndNotif2.fireDate = [current dateByAddingTimeInterval:workSessionInterval2];
    workSessionEndNotif2.timeZone = [NSTimeZone defaultTimeZone];
    workSessionEndNotif2.alertBody = @"You working session finishes. Go to have a rest";
    workSessionEndNotif2.alertAction = @"View";
    workSessionEndNotif2.soundName = UILocalNotificationDefaultSoundName;
    workSessionEndNotif2.applicationIconBadgeNumber = 1;
    [[UIApplication sharedApplication] scheduleLocalNotification:workSessionEndNotif2];
    workSessionEndNotif2 = nil;

    UILocalNotification *workSessionEndNotif3 = [[UILocalNotification alloc] init];
    workSessionEndNotif3.fireDate = [current dateByAddingTimeInterval:workSessionInterval3];
    workSessionEndNotif3.timeZone = [NSTimeZone defaultTimeZone];
    workSessionEndNotif3.alertBody = @"You working session finishes. Go to have a rest";
    workSessionEndNotif3.alertAction = @"View";
    workSessionEndNotif3.soundName = UILocalNotificationDefaultSoundName;
    workSessionEndNotif3.applicationIconBadgeNumber = 1;
    [[UIApplication sharedApplication] scheduleLocalNotification:workSessionEndNotif3];
    workSessionEndNotif3 = nil;

    UILocalNotification *workSessionEndNotif4 = [[UILocalNotification alloc] init];
    workSessionEndNotif4.fireDate = [current dateByAddingTimeInterval:workSessionInterval4];
    workSessionEndNotif4.timeZone = [NSTimeZone defaultTimeZone];
    workSessionEndNotif4.alertBody = @"You working session finishes. Go to have a rest";
    workSessionEndNotif4.alertAction = @"View";
    workSessionEndNotif4.soundName = UILocalNotificationDefaultSoundName;
    workSessionEndNotif4.applicationIconBadgeNumber = 1;
    [[UIApplication sharedApplication] scheduleLocalNotification:workSessionEndNotif4];
    workSessionEndNotif4 = nil;

    UILocalNotification *workSessionEndNotif5 = [[UILocalNotification alloc] init];
    workSessionEndNotif5.fireDate = [current dateByAddingTimeInterval:workSessionInterval5];
    workSessionEndNotif5.timeZone = [NSTimeZone defaultTimeZone];
    workSessionEndNotif5.alertBody = @"You working session finishes. Go to have a rest";
    workSessionEndNotif5.alertAction = @"View";
    workSessionEndNotif5.soundName = UILocalNotificationDefaultSoundName;
    workSessionEndNotif5.applicationIconBadgeNumber = 1;
    [[UIApplication sharedApplication] scheduleLocalNotification:workSessionEndNotif5];
    workSessionEndNotif5 = nil;

    // Schedule rest session ends notifications
    UILocalNotification *restSessionEndNotif1 = [[UILocalNotification alloc] init];
    restSessionEndNotif1.fireDate = [current dateByAddingTimeInterval:restSessionInterval1];
    restSessionEndNotif1.timeZone = [NSTimeZone defaultTimeZone];
    restSessionEndNotif1.alertBody = @"You rest session finishes. Go to work";
    restSessionEndNotif1.alertAction = @"View";
    restSessionEndNotif1.soundName = UILocalNotificationDefaultSoundName;
    restSessionEndNotif1.applicationIconBadgeNumber = 1;
    [[UIApplication sharedApplication] scheduleLocalNotification:restSessionEndNotif1];
    restSessionEndNotif1 = nil;

    UILocalNotification *restSessionEndNotif2 = [[UILocalNotification alloc] init];
    restSessionEndNotif2.fireDate = [current dateByAddingTimeInterval:restSessionInterval2];
    restSessionEndNotif2.timeZone = [NSTimeZone defaultTimeZone];
    restSessionEndNotif2.alertBody = @"You rest session finishes. Go to work";
    restSessionEndNotif2.alertAction = @"View";
    restSessionEndNotif2.soundName = UILocalNotificationDefaultSoundName;
    restSessionEndNotif2.applicationIconBadgeNumber = 1;
    [[UIApplication sharedApplication] scheduleLocalNotification:restSessionEndNotif2];
    restSessionEndNotif2 = nil;

    UILocalNotification *restSessionEndNotif3 = [[UILocalNotification alloc] init];
    restSessionEndNotif3.fireDate = [current dateByAddingTimeInterval:restSessionInterval3];
    restSessionEndNotif3.timeZone = [NSTimeZone defaultTimeZone];
    restSessionEndNotif3.alertBody = @"You rest session finishes. Go to work";
    restSessionEndNotif3.alertAction = @"View";
    restSessionEndNotif3.soundName = UILocalNotificationDefaultSoundName;
    restSessionEndNotif3.applicationIconBadgeNumber = 1;
    [[UIApplication sharedApplication] scheduleLocalNotification:restSessionEndNotif3];
    restSessionEndNotif3 = nil;

    UILocalNotification *restSessionEndNotif4 = [[UILocalNotification alloc] init];
    restSessionEndNotif4.fireDate = [current dateByAddingTimeInterval:restSessionInterval4];
    restSessionEndNotif4.timeZone = [NSTimeZone defaultTimeZone];
    restSessionEndNotif4.alertBody = @"You rest session finishes. Go to work";
    restSessionEndNotif4.alertAction = @"View";
    restSessionEndNotif4.soundName = UILocalNotificationDefaultSoundName;
    restSessionEndNotif4.applicationIconBadgeNumber = 1;
    [[UIApplication sharedApplication] scheduleLocalNotification:restSessionEndNotif4];
    restSessionEndNotif4 = nil;

    UILocalNotification *restSessionEndNotif5 = [[UILocalNotification alloc] init];
    restSessionEndNotif5.fireDate = [current dateByAddingTimeInterval:restSessionInterval5];
    restSessionEndNotif5.timeZone = [NSTimeZone defaultTimeZone];
    restSessionEndNotif5.alertBody = @"You rest session finishes. Go to work";
    restSessionEndNotif5.alertAction = @"View";
    restSessionEndNotif5.soundName = UILocalNotificationDefaultSoundName;
    restSessionEndNotif5.applicationIconBadgeNumber = 1;
    [[UIApplication sharedApplication] scheduleLocalNotification:restSessionEndNotif5];
    restSessionEndNotif5 = nil;
}

我记录了每个通知发出的时间,结果发现只有6个通知会在不同的时间发出。这就是我只收到了6个通知,因为有些是同时安排的


结果是我没有合理安排时间

您在测试期间是否随时打开应用程序?@Wain不,我在测试期间没有打开应用程序。哪些应用程序没有启动?你调试了所有的日期吗?@Wain如果我计划了10个,那么按时间顺序的最后4个将不会启动。你检查了日期并记录了计划的通知(多少个)?