我使用了所有计划通知的列表[[uiapplication sharedApplication]计划列表。
现在,我希望所有射击者的数组与今天的日期进行比较,并给出一个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];
}
}
只需使用" compare:函数:比较两个不同的日期"。像;
一样使用它if(localnotif.fireDate compare:[NSDate date] == NSOrderedSame){
// perform your operation here
}
比较:通过将日期与 nsorderedAscending/nsorderedDescending 。
。