下面是我在互联网上检查过的代码,一切似乎都很好,但不知道通知没有触发我知道它很简单,但我仍然被困在这里,请帮忙
-(void)notification:(NSMutableArray *)nameArray datearray:(NSMutableArray*)datearray;
{
NSLog(@"name%@",nameArray);
NSLog(@"date%@",datearray);
"Jodie Hession",
"John Miller",
"Shane Jarome",
"Sharon Scott",
"Sheron Begley",
"Susan Diaz",
Kate,
John,
Anna,
David,
today,
"After Some day"
)
date(
"14/12/2013 04:35:00",
"18/12/2013 04:35:00",
"04/04/2014 04:35:00",
"01/01/2014 04:35:00",
"29/06/2014 04:35:00",
"05/01/2014 04:35:00",
"18/12/2013 04:35:00",
"20/01/2014 04:35:00",
"22/06/2014 04:35:00",
"29/08/2013 04:35:00",
"15/06/2014 04:35:00",
"22/07/2013 04:35:00",
"31/07/2013 04:35:00"
)
// logic for local notification start
[[UIApplication sharedApplication] cancelAllLocalNotifications];
NSDateFormatter *Form=[[[NSDateFormatter alloc]init]autorelease];
[Form setDateFormat:@"dd/MM/yyyy hh:mm:ss"];
UILocalNotification *notification = [[UILocalNotification alloc] init];
for (int i=0;i<datearray.count;i++)
{
NSDate *date =[Form dateFromString:[datearray objectAtIndex:i ]];
NSLog(@"%@",date);
if(notification)
{
notification.fireDate = date;
// if(notification.fireDate == date){
//
// notification.applicationIconBadgeNumber = 1;
//
// }
notification.timeZone = [NSTimeZone defaultTimeZone];
notification.alertBody = [NSString stringWithFormat:@"Today is %@\'s Birthday",[nameArray objectAtIndex:i]];
notification.alertAction = @"View";
notification.soundName = UILocalNotificationDefaultSoundName;
[[UIApplication sharedApplication] scheduleLocalNotification:notification];
}
NSLog(@"fire date%@", notification.fireDate);
// fire date2013-07-30 23:05:00 +0000
不知道为什么,但是如果我们用 stringfromdate 检查它,nsdate 总是会打印其他东西,那么它只会显示正确的值}
}
在我的应用程序中
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
NSLog(@"Notification Received, %@, set for date %@", notification.alertBody, notification.fireDate);
}