- (void) scheduleGeneralNotificationFrequentlyWithItem:(ToDoItem *)item interval:(int)minutesBefore frequent:(NSCalendarUnit)frequentUnit{
NSCalendar *calendar = [NSCalendar autoupdatingCurrentCalendar];
NSDateComponents *dateComps = [[NSDateComponents alloc] init];
[dateComps setDay:item.day];
[dateComps setMonth:item.month];
[dateComps setYear:item.year];
[dateComps setHour:item.hour];
[dateComps setMinute:item.minute];
NSDate *itemDate = [calendar dateFromComponents:dateComps];
[dateComps release];
UILocalNotification *localNotif = [[UILocalNotification alloc] init];
if (localNotif == nil)
return;
localNotif.fireDate = [itemDate dateByAddingTimeInterval:-(minutesBefore*60)];
localNotif.timeZone = [NSTimeZone defaultTimeZone];
if (!item.eventName) {
item.eventName = @"My event name";
}
localNotif.alertBody = item.alertBody;
localNotif.alertAction = NSLocalizedString(@"Details", nil);
localNotif.soundName = UILocalNotificationDefaultSoundName;
localNotif.applicationIconBadgeNumber = 1;
localNotif.userInfo = item.data; // some data
localNotif.repeatInterval = frequentUnit; // here I put NSDayCalendarUnit
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
[localNotif release];
NSString *isDisableLocalPush = [Settings getSetting:kPraktijDisableLocalPushKey];
if ([isDisableLocalPush isEqualToString:kJSONValueYes]) { //disable all notifications after added it
[self disableAllLocationPushNotifications];
}
}
在上面的代码中,它将每天安排到 localNotif.fireDate ,对吗?
我想要实现的是:安排下个月到下个月的每一天的通知,例如:2013/march/01 到 2013/may/01 的每日通知