2013-04-09 3 views
3

버튼을 통해 약속을 알리는 응용 프로그램이 있습니다. 환자가 버튼을 클릭하면 환자 캘린더의 모든 이벤트를 가져 와서 약속이 이미 있는지 확인하고 싶습니다. 존재하지 않으면, 나는 사건을 창조 할 것이다.iPhone 캘린더에서 모든 일정 가져 오기 시작 날짜가

캘린더에 이벤트를 추가하는 방법을 알고 있지만 페칭은 0을 반환합니다. ??

//set start and end date 
NSDate* startDate = [NSDate date];//start from today 
NSDate* endDate = [NSDate dateWithTimeIntervalSinceNow:[[NSDate distantFuture] timeIntervalSinceReferenceDate]];//no end 
NSLog(@"S Date %@", startDate); 
NSLog(@"E Date %@", endDate); 

NSString *[email protected]"Appointment in Hospital at Pediatric Clinic"; 

EKEventStore *store = [[EKEventStore alloc] init]; 
NSArray *calendarArray = [store calendars]; 
NSPredicate *fetchCalendarEvents = [store predicateForEventsWithStartDate:startDate endDate:endDate calendars:calendarArray]; 
NSArray *eventList = [store eventsMatchingPredicate:fetchCalendarEvents]; 
BOOL IsFound; 
int EventsCount=eventList.count; 
for(int i=0; i < EventsCount; i++) 
{ 
    NSLog(@"Event Title:%@", [[eventList objectAtIndex:i] title]); 
    if ([[[eventList objectAtIndex:i] title] isEqualToString:AppointmentTitle])//check title 
    { 
     IsFound=TRUE; 
     break; 
    } 
    else 
    { 
     IsFound=FALSE; 
    } 
} 

이 코드 2 개월 전 잘 작동되었습니다

다음은 내 코드입니다. 갑자기, 내가 그것을 테스트하기 위해 되돌아 왔을 때, 그것은 효과가 없었습니다. 내가 뭐 놓친 거 없니? 또는 내 코드에 실수가 있습니까?

내가 PLZ 당신의 도움이 필요합니다 .. Finaaaaaaaally

+0

답변 없음 pleeeeease? –

답변

10

내가 대답, 내가 애플에서 iOS 5에서 허가 ( 에 뭔가를했다고 생각있어, 당신은 단지 이벤트 스토어에 액세스 이벤트 (EKEntityTypeEvent)로 사용할 수 있습니다 .. 당신이 알림에 액세스 할 수 있습니다 아이폰 OS (6), (EKEntityTypeReminder)에서하지만 아래의 코드가 필요 달리, 적어도 시간 1) 부여 방법 "WrightsCS 응답"

아래의 코드 찾기 : -

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


// Get the appropriate calendar 
NSCalendar *calendar = [NSCalendar currentCalendar]; 


if ([store respondsToSelector:@selector(requestAccessToEntityType:completion:)]) 
{ 
    /* iOS Settings > Privacy > Calendars > MY APP > ENABLE | DISABLE */ 
    [store requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) 
    { 
     if (granted) 
     { 
      NSLog(@"User has granted permission!"); 
      // Create the start date components 
      NSDateComponents *oneDayAgoComponents = [[NSDateComponents alloc] init]; 
      oneDayAgoComponents.day = -1; 
      NSDate *oneDayAgo = [calendar dateByAddingComponents:oneDayAgoComponents 
                  toDate:[NSDate date] 
                  options:0]; 

      // Create the end date components 
      NSDateComponents *oneYearFromNowComponents = [[NSDateComponents alloc] init]; 
      oneYearFromNowComponents.year = 1; 
      NSDate *oneYearFromNow = [calendar dateByAddingComponents:oneYearFromNowComponents 
                   toDate:[NSDate date] 
                   options:0]; 

      // Create the predicate from the event store's instance method 
      NSPredicate *predicate = [store predicateForEventsWithStartDate:oneDayAgo 
                    endDate:oneYearFromNow 
                    calendars:nil]; 

      // Fetch all events that match the predicate 
      NSArray *events = [store eventsMatchingPredicate:predicate]; 
      NSLog(@"The content of array is%@",events); 
     } 
     else 
     { 
      NSLog(@"User has not granted permission!"); 
     } 
    }]; 
} 
+0

고마워요! 그것은 나에게 많은 도움이 .. – Clement

관련 문제