2013-07-31 1 views
4

나는 문을 나오기 위해 노력하고 있습니다. 이 코드는 원래 다른 팀이 iOS5를 염두에두고 작성했습니다. requestAccessToEntityType : completion : 호출이 성공적으로 실행되었습니다. 그러나 액세스 권한이 부여 된 후에는 엔티티를 기반으로하는 default/calendar 또는 달력이 없습니다. 새 캘린더를 만들 수 없습니다. defaultCalendarForNewEvents를 호출 할 때iOS : EKEventStore sources/defaultCalendarForNewEvents/calendarsForEntityType 모두 승인 후

는이 오류

Error Domain=EKCADErrorDomain Code=1013 "The operation couldn’t be completed. (EKCADErrorDomain error 1013.)"을 얻을 결과는 전무하다.

이 작업을 수행하고 다시 돌아 가려는 viewController에서 나왔다면 모두 정상적으로 작동합니다. 소스가 없다는 경고를받은 후 viewController를 제거하지 않고 계속 시도하면 반복적으로 실패합니다.

나는 권한 부여 요청이 작동한다는 것을 강조하고 싶다. (사용자는 일정에 대한 액세스 권한을 부여하고 권한을 부여한 다음 권한 부여 확인을 요청한다.) 호출됩니다 : - 유사하다 내가 찾은 다른 모든 질문은 솔루션 있음이 확인하는 당신은

[eventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) { 
    if (granted) 
     { 
     //[self performSelectorOnMainThread:@selector(doScheduleActivity:) withObject:activity waitUntilDone:YES]; 
      dispatch_async(dispatch_get_main_queue(), ^{ 
       [self doScheduleActivity:activity]; 
       }); 
      } 
     else 
     { // probably should force the main thread 
     dispatch_async(dispatch_get_main_queue(), ^{ 
      UIAlertView *av = [[UIAlertView alloc] initWithTitle:@"Calendar Access Required" message:@"In order to schedule activities, APP needs access to your Calendar. You can change this in your device Settings." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; 
      [av show]; 
      }); 
     } 

}] ; 

granted 다시 진정한 와서 [자기 doScheduleActivity이 requestAccessToEntityType. 다음 코드는 해당 루틴의 맨 처음에 호출 된 함수이며 실패한 부분입니다.

EKCalendar *saCalendar; 
EKSource *source; 
NSError *error; 
UIAlertView *alert; 

LogDebug(@"eventStore defaultCalendar %@", [eventStore defaultCalendarForNewEvents]); 

// validate access to calendar prior to segueing 
if ([EKEventStore respondsToSelector:@selector(authorizationStatusForEntityType:)]) 
{ 
    switch([EKEventStore authorizationStatusForEntityType:EKEntityTypeEvent]) 
    { 
     case EKAuthorizationStatusAuthorized: 
      break; 
     case EKAuthorizationStatusNotDetermined: 
      { 
       dispatch_async(dispatch_get_main_queue(), ^{ 
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:SA_ALERT_CAPTION_CALENDAR_ACCESS_NOT_DETERMINED message:SA_ALERT_BODY_CALENDAR_ACCESS_NOT_DETERMINED delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil]; 
        [alert show]; 
        }); 
       return false; 
       } 
     case EKAuthorizationStatusDenied: 
      { 
       dispatch_async(dispatch_get_main_queue(), ^{ 
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:SA_ALERT_CAPTION_CALENDAR_ACCESS_DENIED message:SA_ALERT_BODY_CALENDAR_ACCESS_DENIED delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil]; 
        [alert show]; 
        }); 
       return false; 
       } 
     case EKAuthorizationStatusRestricted: 
      { 
       dispatch_async(dispatch_get_main_queue(), ^{ 
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:SA_ALERT_CAPTION_CALENDAR_ACCESS_RESTRICTED message:SA_ALERT_BODY_CALENDAR_ACCESS_RESTRICTED delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil]; 
        [alert show]; 
        }); 
       return false; 
       } 
     default: 
      break; 
    } 
} 

// search for application specifc calendar.. 
saCalendar = nil; 
for(EKCalendar *calendar in [eventStore calendarsForEntityType:EKEntityTypeEvent]) 
{ 
    if([calendar.title isEqualToString:SA_ACTIVITIES_CALENDAR_TITLE]) 
    { 
     saCalendar = calendar; 
     break; 
    } 
} 
// ..and create from scratch if nonexistent 
if(nil == saCalendar) 
{ 
    // find local source to hook up new calendar to 
    for(source in [eventStore sources]) 
    { 
     if(source.sourceType == EKSourceTypeLocal) 
     { 
      break; 
     } 
    } 

    // if could not find local source type, something is wrong 
    if(source == nil || source.sourceType != EKSourceTypeLocal) 
    { 
     alert = [[UIAlertView alloc] initWithTitle:SA_ALERT_CAPTION_CALENDAR_ERROR_NO_SOURCE message:SA_ALERT_BODY_CALENDAR_ERROR delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil]; 
     [alert show]; 
     return false; 
    } 

    // create calendar for applcation, name it, color it and assign source 
    saCalendar = [EKCalendar calendarForEntityType:EKEntityTypeEvent eventStore:eventStore]; 
    [saCalendar setSource:source]; 
    [saCalendar setTitle:SA_ACTIVITIES_CALENDAR_TITLE]; 
    [saCalendar setCGColor:[[UIColor yellowColor] CGColor]]; 

    // create immediately 
    error = nil; 
    if(![eventStore saveCalendar:saCalendar commit:true error:&error]) 
    { 
     dispatch_async(dispatch_get_main_queue(), ^{ 
      UIAlertView *alert = [[UIAlertView alloc] initWithTitle:SA_ALERT_CAPTION_CALENDAR_ERROR_CANT_SAVE message:SA_ALERT_BODY_CALENDAR_ERROR delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil]; 
      [alert show]; 
      }); 
     return false; 
    } 
} 

return true; 

모든이 허가했다하더라도 전무 다시 와서 내가 여기에 실패를 얻을 후 [EKEventStore authorizationStatusForEntity:EKEntityType 수익률 검사가 다시 가서 다시이보기 컨트롤러 중 I 경우, 작동,

을 EKAuthorizationStatusAuthorized. 이는 시스템이 사용자에게 캘린더 액세스를 요청한 후 처음으로 확인 응답을하는 경우에만 발생합니다.

어떤 통찰력에도 감사드립니다. 나는 디버거를 밟아 왔고, 또한 어떤 종류의 타이밍 문제를 피하기 위해 printf 형식의 디버깅을하고 있었고, 애플 사이트에서 찾은 이벤트와는 아무런 관련이 없다.

내 대상 장치 6.1.3 아이폰 5

답변

6

OK이고, 상기 [eventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error 코드 앞에이었고 즉 eventStore 액세스하기 위해 시도한 viewDidLoad에 코드의 작은 라인 거기 나온다. 그것은 불필요하고 일어날 필요가 없었고 나는 그것을 알아 채지 못했습니다. 일단이 코드를 제거하면 내용이 작동하므로 권한 부여 후에도 이전에 액세스 한 것으로 인해 eventStore가 이미 "불량"이었기 때문에 권한 부여가 필요한 상태로 되돌아갑니다.

7

액세스가 허가되면 콜백에 EKEventStore 인스턴스를 다시 만들어 문제를 해결할 수도 있습니다.

+0

이 문제가 해결 된 것으로 보입니다. 그러나 실제 문제가 무엇인지 찾을 수 없었습니다. 어떤 생각? –

+1

권한이 부여되기 전에 이벤트 저장소에 액세스하려고하면 iOS 버그 일 뿐이라고 생각합니다. – zeroimpl