2015-02-01 5 views
10

캘린더 앱을 개발 중입니다. 할당 된 EKCalender를 사용하여 EKEvent를 저장하려고합니다. 하지만 다음 코드를 실행하려고하면 오류가 발생합니다. 위의 코드엔티티 유형 3, Xcode 6.1.1에 대한 공유 캘린더 초대장을 가져 오는 중에 오류가 발생했습니다. EKCalender, EKSource, EKEventstore 및 Objective C

-(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; 
    } 

도와주세요 오류 다음 부여합니다

가 어떻게 그것을하시기 바랍니다 제거 할 수

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.)" 
?

답변

12

내 앱에서 동일한 문제가 발생했습니다. calendarWithIdentifier 메서드가 호출 될 때 오류가 발생하는 것으로 나타났습니다.

정확하게 발생하는 이유는 모르겠지만 기기에 공유 캘린더가 없을 때 발생합니다. 오프 물론 아주 좋은 방법은 아니지만 오류가 사라

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

: 여기에 링크 About shared iCloud calendars

내가 솔루션 here을 발견하고 난 다음 코드로 내 응용 프로그램에 고정합니다. 희망 사항 :

+1

공유 캘린더가없는 경우에만 힌트가 표시 될 수 있습니다. – ctietze

+0

나는 캘린더를 공유하고 있지만 iCloud가 아닌 Google을 사용하는 기기에서이 모든 것을 얻습니다. 그것은 기능에 영향을 미치지 않는 것 같지만, 로그를 쓰레기로 범람시키기 때문에 PITA를 디버깅합니다. –

+0

위대한 작품.고마워요 많은 :) –

0

이 오류의 또 다른 원인은 일정을 생성하는 엔티티 유형 매개 변수에 EKEntityTypeEvent 유형 대신 비트 마스크 EKEntityMaskEvent을 사용하는 것입니다.

당신은 같은 달력을 만들려고하면 그런 다음 일정이 잘 식별자로 반환됩니다

EKCalendar *calendar = [EKCalendar calendarForEntityType:EKEntityMaskEvent eventStore:self.eventStore]; 

하지만, 일정이 유효하지 보인다 오류가 얻을 수 없지만 그것을 저장할 수 없습니다. 이벤트를 추가 할 수 없습니다. calendarWithIdentifier은 nil을 리턴합니다. 올바른 구문을 사용

EKEntityTypeEvent 같은 : 나는 이벤트를 달력에 미리 알림 작업에서 전환 할 때 참조 할 수 있도록

EKCalendar *calendar = [EKCalendar calendarForEntityType:EKEntityTypeEvent eventStore:self.eventStore]; 
0

오래된 질문하지만, 나는이 문제를 가지고 있었다. 모든 장소에서 엔티티 유형을 변경하는 것을 잊었습니다.

특히, 내가

EKAuthorizationStatus authorizationStatus = [EKEventStore authorizationStatusForEntityType:EKEntityTypeReminder]; 

와 EKEntityType 알림 내 권한의 상태를로드하고 후자 그래서

[self.eventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) { 
    if (error == nil) { 
     // Store the returned granted value. 
    } else { 
     NSLog(@"%@", [error localizedDescription]); 
    } 
}]; 

와 EKEntityType 이벤트에 대한 사용자 권한을 요청하고, 용액 내 권한 상태 점검을 다음과 같이 변경했습니다.

EKAuthorizationStatus authorizationStatus = [EKEventStore authorizationStatusForEntityType:EKEntityTypeEvent];