2013-02-04 6 views
0

권한이없는 경우 어떻게 오류를 표시 할 수 있습니까? (예 : "당신은 우리에게 당신의 달력에 글쓰기를 허락하지 않습니다.").권한 달력 이벤트 추가 iOS

if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"6.0")) { 

EKEventStore *es = [[EKEventStore alloc] init]; 
[es requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) { 
    /* This code will run when uses has made his/her choice */ 
}]; 
} 
     NSDateFormatter * dateFormatter = [[NSDateFormatter alloc] init]; 
     [dateFormatter setDateFormat:@"ddMMyy"]; 

     NSString *fechainicio = datum; 
     NSString *fechafin = datum; 
     titel = [NSString stringWithFormat:@"%@ (%@)", titel, plaatslabel.text]; 

     NSDate * date = [[NSDate alloc] init]; 
     date = [dateFormatter dateFromString:fechainicio]; 
     NSDate * date2 = [[NSDate alloc] init]; 
     date2 = [dateFormatter dateFromString:fechafin]; 

     EKEventStore *eventStore = [[EKEventStore alloc] init]; 

     EKEvent *event = [EKEvent eventWithEventStore:eventStore]; 
     event.title  = @"Optreden Ronald Goedemondt"; 
     event.location = titel; 
     event.allDay = YES; 

     event.startDate = date; 
     event.endDate = date2; 

     [event setCalendar:[eventStore defaultCalendarForNewEvents]]; 
     NSError *err; 
     [eventStore saveEvent:event span:EKSpanThisEvent error:&err]; 

WBSuccessNoticeView *notice = [WBSuccessNoticeView successNoticeInView:self.view title:@"Show geplaatst in uw agenda."]; 
[notice show]; 

답변

8

granted 중 하나를 액세스 권한이 부여 된 경우 YES 또는 NO 그렇지 않으면 될 것입니다.
또한, 그렇게하는 것이 필요한 때 만 -requestAccessToEntityType:completion: 전화 있는지 확인해야합니다 :

EKEventStore *es = [[EKEventStore alloc] init]; 
EKAuthorizationStatus authorizationStatus = [EKEventStore authorizationStatusForEntityType:EKEntityTypeEvent]; 
BOOL needsToRequestAccessToEventStore = (authorizationStatus == EKAuthorizationStatusNotDetermined); 

if (needsToRequestAccessToEventStore) { 
    [es requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) { 
     if (granted) { 
      // Access granted 
     } else { 
      // Denied 
     } 
    }]; 
} else { 
    BOOL granted = (authorizationStatus == EKAuthorizationStatusAuthorized); 
    if (granted) { 
     // Access granted 
    } else { 
     // Denied 
    } 
} 
+0

고마워, 잘된거야! – AYS

3

여기 내가 사용하는 코드입니다 :

내 코드입니다. 작품 매력 :

-(void)askPermissionForCalendarAccess { 
    EKEventStore *eventStore = [[EKEventStore alloc] init]; 
    /* iOS 6 requires the user grant your application access to the Event Stores */ 
    if ([eventStore respondsToSelector:@selector(requestAccessToEntityType:completion:)]) 
    { 
     /* iOS Settings > Privacy > Calendars > MY APP > ENABLE | DISABLE */ 
     [eventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) { 

      if (granted) { 

       NSLog(@"granted"); 
       //This method checks to make sure the calendar I want exists, then move on from there... 
       [self checkForCalendar]; 

      } else { 

       //put error popup code here. 
       NSLog(@"denied"); 
       [self performSelectorOnMainThread:@selector(showDeniedAccessAlert) withObject:nil waitUntilDone:NO]; 
      } 
     }]; 
    } 
} 
+0

나는 – AYS

+0

지금보십시오 ... self.eventStore respondsToSelector에 의해 오류가 발생합니다. 나는 당신을 위해 나의 코드를 조정했다. 내보기 컨트롤러의 속성으로 이벤트 저장소를 사용하고있었습니다. – jhilgert00

+0

액세스가 거부되면 응용 프로그램이 중단됩니다. – AYS