2012-10-31 86 views
0

中的预定通知数组的计划通知列表我使用 [[UIApplication sharedApplication] scheduledLocalNotifications]获得了所有计划通知的列表。比较今天的日期和使用iphone

现在我想要所有火焰阵列与今天的日期进行比较,并给予alertview告诉今天到期的提醒。 我是这样做的,但不知道它是否会正常工作。请改正我对iphone开发的新看法。

NSArray *arrayoflocalnotifications = [[NSArray alloc] initWithArray:[[UIApplication sharedApplication]scheduledLocalNotifications]]; 

for (UILocalNotification *localnotif in arrayoflocalnotifications) 
{ 
    NSLog(@"array of firedate is %@", localnotif); 

    if ([localnotif.fireDate isEqualToDate:[NSDate date]]) 
    { 
     NSLog(@"Got a duetoday reminder..."); 

     UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"AlertView" message:@"Due reminder for today" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok", nil]; 
     [alert show]; 
     [alert release]; 
    } 

} 

回答

0

只是使用compare:函数来比较两个不同的日期。像使用它一样;

if(localnotif.fireDate compare:[NSDate date] == NSOrderedSame){ 
// perform your operation here 
} 

比较:让你灵活地比较,如果该日期之前或通过比较NSOrderedAscending/NSOrderedDescending特定日期之后。

+0

我试过你的建议,但很困惑,我怎么能显示那些匹配在我的tableview和alertview以及火候。 – Mak13

+1

嗨@疯狂-36我解决它像这样 - 转换今天的日期,并从字符串格式arrayoflocalnotifications和比较,我们可以得到提醒/通知,将触发今天。 – Mak13

+0

好;)保持它 – Sandeep

相关问题