我想在目標日期前2天之前發出通知。目前我正在使用以下代碼來觸發通知,但是存在如何在定位日期前2天準確觸發通知。NSNotification從目標日期前2天
NSString *frstdate = [[calenderarray objectAtIndex:k] objectForKey:@"date"];
NSLog(@"frstdate..%@",frstdate);
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"yyyy-MM-dd"];
NSDate *date = [dateFormat dateFromString:frstdate];
NSLog(@"date..%@",date);
NSDate *dateToFire = [[[NSDate alloc] initWithTimeInterval:-24*60*60 sinceDate:date]autorelease];
NSLog(@"dateToFire..%@",dateToFire);
UILocalNotification *localNotif = [[UILocalNotification alloc] init];
if (localNotif == nil)
return;
localNotif.fireDate = itemDate;
localNotif.alertAction = @"View";
localNotif.soundName = UILocalNotificationDefaultSoundName;
localNotif.applicationIconBadgeNumber = 1;
localNotif.userInfo = [NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"Get Food"], @"foodItem", nil] ;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
[localNotif release];
Thanks in advance.
什麼是'itemDate'?你有意在那裏寫'dateToFire'嗎? – user1118321
您是否使用本機日曆應用來添加這些事件 –
是的,我使用本機日曆應用添加事件。 – vishal