XCode:为什么我的活动没有被添加到日历中?

时间:2011-10-10 20:02:32

标签: objective-c ios xcode uidatepicker eventkit

我已将以下代码添加到我的应用中:

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日历中添加任何内容?

感谢。

1 个答案:

答案 0 :(得分:8)

您的活动需要有效的时间跨度才能保存。试试这个

event.startDate = selected;
event.endDate = [selected dateByAddingTimeInterval:30*60]; //30 minutes for example