我想在没有用户界面的情况下设置日历提醒。意味着我将NSDate对象设置为日历。怎么做到呢。我已经完成了UIEventKit框架。但它需要用户界面互动。
寻找你的建议。
答案 0 :(得分:1)
幸运的是,我刚刚为其中一个应用程序编写了此代码。调整它以适应您的应用程序。 当然可以正确处理错误。
-(void)makeCalendarEntryWithTitle:(NSString *)title startDate:(NSDate *)startDate endDate:(NSDate *)endDate location:(NSString *)location
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
EKEventStore *eventStore = [[EKEventStore alloc] init];
EKEvent *anEvent = [EKEvent eventWithEventStore:eventStore];
anEvent.calendar = eventStore.defaultCalendarForNewEvents;
anEvent.title = title;
anEvent.startDate = startDate;
anEvent.endDate = endDate;
anEvent.location = location;
//alarm before 5 minutes of the event
anEvent.alarms = [NSArray arrayWithObjects:[EKAlarm alarmWithRelativeOffset:-300],nil];
NSError *error;
[eventStore saveEvent:anEvent span:EKSpanThisEvent error:&error];
if(error)
{
NSLog(@"Error description - %@",[error localizedDescription]);
}
[pool drain];
}