如何为多个值设置本地通知?

时间:2012-06-29 07:45:43

标签: iphone objective-c ios uilocalnotification

任何人都可以告诉我如何在不同的时间为不同的值设置通知..

假设我有一个大小为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");
}

1 个答案:

答案 0 :(得分: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)
}