XCode:为什么我的活动没有被添加到日历?
我已经将下面的代码添加到我的应用程序中:
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日历?
谢谢。
您的活动需要一个有效的时间跨度来保存。 尝试这个
event.startDate = selected; event.endDate = [selected dateByAddingTimeInterval:30*60]; //30 minutes for example