簡體   English   中英

我安排了10個iOS UILocalNotification,但只有6個被解雇了

[英]I scheduled 10 iOS UILocalNotification, but only 6 got fired

我寫了預定的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條通知,因為有些通知是在同一時間安排的。

原來,我沒有正確安排時間。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM