0

UILocalNotification を 10 個予定して書いたのですが、発火したのは 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;
}
4

1 に答える 1

0

各通知が発生する時間を記録したところ、異なる時間に発生するのはそのうちの 6 つだけであることがわかりました。つまり、いくつかの通知が同時にスケジュールされているため、6 つの通知しか受け取りませんでした。

時間を適切にスケジュールしていなかったことが判明しました。

于 2013-08-15T03:28:52.670 に答える