我已将以下代码添加到我的应用中:
NSDate * selected = [DatePicker date];
NSString * date = [selected description];
NSDateComponents *components = [[NSCalendar currentCalendar] components:NSDayCalendarUnit
fromDate:DatePicker.date];
CalLabel1.text = [NSString stringWithFormat:@"%d", [components day]];
EKEventStore *store = [[EKEventStore alloc] init];
EKEvent *event = [EKEvent eventWithEventStore:store];
event.title = @"Test Event";
//required
event.startDate = [DatePicker date];
event.endDate = [DatePicker date];
event.calendar = store.defaultCalendarForNewEvents;
//end
NSError *err;
[store saveEvent:event span:EKSpanThisEvent error:&err];
为什么这不会在iOS日历中添加任何内容?
感谢。
答案 0 :(得分:8)
您的活动需要有效的时间跨度才能保存。试试这个
event.startDate = selected;
event.endDate = [selected dateByAddingTimeInterval:30*60]; //30 minutes for example