我有一个以编程方式创建日历的代码,在模拟器上可以正常但在iphone上它不起作用。在我的iphone上,日历与iCloud相关联(也许这就是原因)。
每次运行代码时,我都会收到消息,告知它已创建,并且是标识符:
[eventStore saveCalendar:calendar commit:YES error:&error];
if (!error) {
NSLog(@"created, saved, and commited my calendar with id %@", calendar.calendarIdentifier);
}
答案 0 :(得分:0)
我解决了......问题是因为iCloud,这是我的解决方案:
NSArray *allCalendars = [eventStore calendarsForEntityType:EKEntityTypeEvent];
for (int i=0; i<allCalendars.count; i++) {
EKCalendar *currentCalendar = [allCalendars objectAtIndex:i];
if ([currentCalendar.title isEqualToString:@"tapCar"]) // YES
{
calendarIdentifier = currentCalendar.calendarIdentifier;
calendarexiste=@"ok";
}
}
if ([calendarexiste isEqualToString:@"ok"]) // YES
{
NSLog(@"there is a calendar");
calendar = [eventStore calendarWithIdentifier:calendarIdentifier];
} else {
NSLog(@"there is no calendar");
// Create a new calendar of type Local... save and commit
calendar = [EKCalendar calendarForEntityType:EKEntityTypeEvent eventStore:eventStore];
calendar.title = @"tapCar";
UIColor *bluecolor = [UIColor colorWithRed:(16/255.0) green:(161/255.0) blue:(233/255.0) alpha:1];
[calendar setCGColor:bluecolor.CGColor];
EKSource *theSource = [eventStore defaultCalendarForNewEvents].source;
calendar.source=theSource;
NSError *error = nil;
[eventStore saveCalendar:calendar commit:YES error:&error];
if (!error) {
NSLog(@"created, saved, and commited my calendar with id %@", calendar.calendarIdentifier);
} else {
NSLog(@"an error occured when creating the calendar = %@", error.description);
error = nil;
}
}
event.calendar=calendar;
但现在我遇到以下错误:从守护程序获取实体类型3的共享日历邀请时出错:错误域= EKCADErrorDomain代码= 1013&#34;操作无法完成。 (EKCADErrorDomain错误1013。)&#34;
有人知道为什么吗?