0

異なる時間に異なる値の通知を設定する方法を教えてください..

サイズ4の配列があるとします。

たとえば、配列 a={1,2,3};

私が欲しいのは、1時間ごとに異なる配列値の通知が表示されることです。

最初は「1」、1 時間後に「2」、3 時間後に「3」と表示されます。

私が実装したコードは、以下に示す1つの値のみです...

NSDate *fireDate = [NSDate date];

NSArray *values= [NSArray arrayWithObjects:@"1", @"2", @"3", nil];

for (NSString *string in values ) 

{
    // create notification...

    localNotify.fireDate =[NSDate dateWithTimeIntervalSinceNow:[datePicker countDownDuration]];

    localNotify.alertBody = string;

    [[UIApplication sharedApplication] scheduleLocalNotification:localNotify];

    fireDate = [fireDate dateByAddingTimeInterval:67]; 

    [localNotify setApplicationIconBadgeNumber:[[UIApplication sharedApplication] applicationIconBadgeNumber]+1];

    NSLog(@"1");
}
4

1 に答える 1

4

ループを使用するだけです。例:

NSDate *fireDate = [NSDate dateWithTimeIntervalSinceNow:[datePicker countDownDuration]];
for (NSString *string in values [NSArray arrayWithObjects:@"1", @"2", @"3", nil])
{
    // create notification...
    localNotify.fireDate = fireDate;
    localNotify.alertBody = string;
    [[UIApplication sharedApplication] scheduleLocalNotification:localNotify];
    fireDate = [fireDate dateByAddingTimeInterval:60 * 60]; // (1 hour)
}
于 2012-06-29T07:57:38.137 に答える