use*_*630 13 iphone xcode objective-c ekeventkit ekeventstore
我正在开发日历应用程序.我正在尝试使用指定的EKCalender保存EKEvent.但是,当我尝试运行以下代码时,它给了我错误.请帮忙
-(BOOL)createEventWithTitle:(NSString *)paramTitle startDate:(NSDate *)paramStartDate endDate:(NSDate *)paramEndDate inCalendar:(EKCalendar *)paramCalendar inEventStore:(EKEventStore *)paramStore notes:(NSString *)paramNotes
{
BOOL result = NO;
//paramCalendar = [self.eventStoreiReportShifts defaultCalendarForNewEvents];
if (self.eventsAccessGranted) {
NSArray *caledars = [self.eventStore calendarsForEntityType:EKEntityTypeEvent];
self.selectedCalendarEventKitIdentifier = [[NSUserDefaults standardUserDefaults] objectForKey:@"eventkit_cal_identifiers_string"];
for(EKCalendar *aCal in caledars){
if([aCal.calendarIdentifier isEqualToString:self.selectedCalendarEventKitIdentifier]){
paramCalendar = [self.eventStore calendarWithIdentifier:[[NSUserDefaults standardUserDefaults] objectForKey:@"eventkit_cal_identifiers_string"]];
}
}
for (EKSource *source in self.eventStore.sources) {
if (source.sourceType == EKSourceTypeCalDAV) {
paramCalendar.source = source;
break;
} else if(source.sourceType == EKSourceTypeLocal){
paramCalendar.source = source;
break;
}
}
}else{
return NO;
}
/* If a calendar does not allow modification of its contents
then we can not insert an event into it */
if (paramCalendar.allowsContentModifications == NO) {
NSLog (@ "\n\n The selected calendar does not allow modifications.");
return NO;
}
/* Create an event */
EKEvent * event = [EKEvent eventWithEventStore:paramStore];
event.calendar = paramCalendar;
/* Set the properties of the event such as its title,
start date / time, end date / time, etc. */
event.title = paramTitle;
event.notes = paramNotes;
event.startDate = paramStartDate;
event.endDate = paramEndDate;
/* Finally, save the event into the calendar */
NSError * saveError = nil;
result = [paramStore saveEvent:event
span:EKSpanThisEvent
error:&saveError];
if (result == NO) {
NSLog (@ "\n\n An error occurred = %@", saveError);
}
return result;
}
Run Code Online (Sandbox Code Playgroud)
上面的代码给出了以下错
CalendarCalculations[1668:45103]
Error getting shared calendar invitations for entity types 3 from
daemon: Error Domain=EKCADErrorDomain Code=1013
"The operation couldn’t be completed. (EKCADErrorDomain error 1013.)"
Run Code Online (Sandbox Code Playgroud)
我怎么能摆脱它呢?
Lem*_*Sun 16
我的应用程序中遇到了同样的问题.我注意到calendarWithIdentifier调用方法时发生错误.
EKCalendar *selectedCalendar = [self.eventStore calendarWithIdentifier:selectedCalendarIdentifier];
Run Code Online (Sandbox Code Playgroud)
我不确切地知道它为什么会发生,但我想当你的设备中没有任何共享日历时会发生这种情况.这是关于共享iCloud日历的链接
我在这里找到了解决方案,并使用下一个代码片段在我的应用中修复了它:
EKCalendar *selectedCalendar = [EKCalendar calendarForEntityType:EKEntityTypeEvent eventStore:self.eventStore];
NSString *selectedCalendarIdentifier = [[NSUserDefaults standardUserDefaults] objectForKey:@"selectedCalendarIdentifier"];
//instead of getting calendar by identifier
//get all calendars and check matching in the cycle
NSArray *allCalendars = [self.eventStore calendarsForEntityType:EKEntityTypeEvent];
for (EKCalendar *calendar in allCalendars) {
if ([calendar.calendarIdentifier isEqualToString:selectedCalendarIdentifier]) {
selectedCalendar = calendar;
break;
}
}
Run Code Online (Sandbox Code Playgroud)
当然,这不是很好的方式,但错误消失了.希望它会帮助你;)
| 归档时间: |
|
| 查看次数: |
4939 次 |
| 最近记录: |