2016-10-21 6 views
0

ユーザーが最初にアプリケーションを開くと、私は日付を保存し、毎日特定の時間に30日間、地元の通知を送信するというアプリがあります。毎日違う必要があります。各メッセージは、その日の出来事を思い出させるものです。設定された日数のための別のUIlocalnotificationを起動しない

はAppdelegateで私はその後、私は現在の日付に1日を追加して、私のschedulenotificatonsメソッドを呼び出すforループを持っている

loadNotif方法で
- (void)applicationDidEnterBackground:(UIApplication *)application { 

NSDateFormatter *dateFormatter1 = [[NSDateFormatter alloc] init]; 
[dateFormatter1 setDateFormat:@"yyyy-MM-dd HH:mm:ss"]; 
NSDate *date = [NSDate date]; 
NSLog(@"date : %@",date); 

NSTimeZone *currentTimeZone = [NSTimeZone localTimeZone]; // <- Local time zone 
NSTimeZone *utcTimeZone = [NSTimeZone timeZoneWithAbbreviation:@"UTC"]; 

NSInteger currentGMTOffset = [currentTimeZone secondsFromGMTForDate:date]; 
NSInteger gmtOffset = [utcTimeZone secondsFromGMTForDate:date]; 
NSTimeInterval gmtInterval = currentGMTOffset - gmtOffset; 

NSDate *destinationDate = [[NSDate alloc] initWithTimeInterval:gmtInterval sinceDate:date]; 
NSLog(@"date : %@",destinationDate); 

[self loadNotif:destinationDate]; 

} 

があるメソッドを呼び出して、現在の時刻に日付を設定しました

-(void)loadNotif:(NSDate *)notifDate { 
NSLog(@" date %@", notifDate); 
NSString *alertMSG = @""; 

NSDateComponents *dayComponent = [[NSDateComponents alloc] init]; 
    for (int i = 0; i <= 3; i++) { 


dayComponent.second = i; 
    if (i == 0) { 
     alertMSG = @"Checkout Today's Video! Sustainable Posture!"; 
    } else if (i == 1) { 
     alertMSG = @"Checkout Today's Video! Forward Head!"; 
    } else if (i == 2) { 
     alertMSG = @"Checkout Today's Video! Neck Position!"; 
    } else if (i == 3) { 
     alertMSG = @"Checkout Today's Video! Shoulder Position!"; 
    } 

    notifDate = [notifDate dateByAddingTimeInterval:5]; 
    [self scheduleNotificationForDate:notifDate AlertBody:alertMSG ActionButtonTitle:@"30 Day Posture Challenge" NotificationID:alertMSG]; 

NSLog(@"nextDate: %@ ... %@", notifDate, alertMSG); 
} 
} 

テスト目的のために、私は彼らが働いているかどうかを確認するために5秒追加しています。

-(void) scheduleNotificationForDate:(NSDate *)date AlertBody:(NSString *)alertBody ActionButtonTitle:(NSString *)actionButtonTitle NotificationID:(NSString *)notificationID{ 
UILocalNotification *localNotification = [[UILocalNotification alloc] init]; 

NSLog(@"firedate %@", date); 

localNotification.fireDate = date; 
localNotification.timeZone = [NSTimeZone localTimeZone]; 
localNotification.alertBody = alertBody; 
localNotification.alertAction = actionButtonTitle; 
localNotification.soundName=UILocalNotificationDefaultSoundName; 

localNotification.applicationIconBadgeNumber= + 1; 

NSDictionary *infoDict = [NSDictionary dictionaryWithObject:notificationID forKey:@"notifID"]; 
localNotification.userInfo = infoDict; 

[[UIApplication sharedApplication] scheduleLocalNotification:localNotification]; 

} 

私が抱えている問題は、すべての通知を同時に発生させることです。これがなぜ起こっているのか?

+0

ログメッセージの内容は何ですか? – matt

+0

ログメッセージは、firedateが正しく機能することを示しています。 5秒で各ループが追加された2016-10-20 20:10:41.328 firedate 2016-10-20 20:10:46 +0000 firedate 2016-10-20 20:10:51 +0000 –

+0

私が考えることができる唯一のことたぶん5秒はあまりに細かすぎます。システムはあなたのためにこれらの事柄を提供しているので、それらを一緒にまとめる方法を判断します。だからそれは目的にそれらを組み合わせているかもしれません。それで、たとえそれが苦痛であっても、それを数分置き、あなたがどう行くかを見てください。 – matt

答えて

0

私は手足に出て、GMTとタイムゾーンのジッゲリーポケリーがあなたを悩ませていることを示唆しています。私はそれが何をすべきか分からないが、それは私の目を越える。ここから5秒後にローカル通知をスケジュールするには、1ライナーが必要です。

私はこのようなことをしておきたいと思います。通知スケジューラに何秒も渡してください。

関連する問題