我正在使用一个简单的代码以编程方式存储日历事件我在堆栈上搜索了许多解决方案,但所有这些都在 SWIFT stack-1 stack -2中提到并且我正在使用< strong> Object-C 这里是我使用的代码:
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];
[dateFormatter setDateFormat:@"MM/dd/yyyy"];
EKEventStore *store = [EKEventStore new];
[store requestAccessToEntityType:EKEntityMaskEvent completion:^(BOOL granted, NSError *error) {
NSLog(@"%@",error);
if (!granted) { return; }
EKEvent *event = [EKEvent eventWithEventStore:store];
event.title = @"Restaurant Table";
event.startDate = [NSDate date];
// event.endDate = [event.startDate dateByAddingTimeInterval:60*60]; //set 1 hour meeting
event.calendar = [store defaultCalendarForNewEvents];
NSError *err = nil;
[store saveEvent:event span:EKSpanThisEvent commit:YES error:&err];
// self.savedEventId = event.eventIdentifier; //save the event id if you want to access this later
}];
提前致谢 这里的源代码为Programmatically add custom event in the iPhone Calendar