开发者

XCode: Why is my event not being added to the calendar?

I have added the following code to my app:

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];

Why is this not adding anything to the iOS calendar?

Thanks.


Your event needs a valid time span to save it. Try this

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜