0

谁能告诉我如何在不同的时间为不同的值设置通知..

假设我有一个大小为 4 的数组,

例如数组 a={1,2,3};

我想要的是每小时后它会显示不同数组值的通知;

第一次显示“1”,一小时后显示“2”,第三小时显示“3”。

我实现的代码仅适用于一个值,如下所示...

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 回答