2012-09-11 2 views
1

iPhone 캘린더를 사용하여 하나의 간단한 응용 프로그램을 만들고 있는데, iPhone 기본 달력 이벤트를 iPhone 응용 프로그램으로 가져와야합니다. 어떻게해야합니까? 코드 조각이 있지만 작동하지 않는 것 같습니다. 내 iPhone 기본 캘린더에 일정을 추가했습니다. 하지만 검색 할 때 아무것도 가져 오지 않습니다. 여기에 코드 조각이 있습니다.iPhone - 기본 캘린더 일정을 내 iPhone 앱으로 가져 오는 방법은 무엇입니까?

-(IBAction)importCalEvents:(id)sender 
{ 
    NSArray *caleandarsArray = [[NSArray alloc] init]; 
    caleandarsArray = [[eventStore calendars] retain]; 
    NSLog(@"Calendars from Array : %@", caleandarsArray); 

for (EKCalendar *CalendarEK in caleandarsArray) 
{ 
    NSLog(@"Calendar Title : %@", CalendarEK.title);  
}   
} 

답변

3

이와 같이 모든 캘린더 일정을 가져올 수 있습니다.

이 2 개의 프레임 워크를 가져옵니다 (프로젝트에 없으면 추가하십시오)./EventKit.h

2) EventKitUI/EventKitUI.h

전화

1 EventKit 버튼에이 기능을

-(void)EventList{ 

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

    NSDate *startDate = [[NSDate alloc] init]; 
    NSDate *endDate = [[NSDate alloc] initWithTimeInterval:3600 sinceDate:startDate]; 

    NSArray *calendars = [eventStore calendars]; 
    NSPredicate *predicate = [eventStore predicateForEventsWithStartDate:startDate 
                   endDate:endDate calendars:calendars]; 
    NSArray *matchingEvents = [eventStore eventsMatchingPredicate:predicate]; 
    EKEvent *anEvent; 

    NSLog(@"Total Events >> %d",[matchingEvents count]); 

    for (int j=0; j < [ matchingEvents count]; j++) { 

     anEvent = [matchingEvents objectAtIndex:j]; 

     NSLog(@"Title >>>%@",anEvent.title); 
     NSLog(@"start date is %@ \n End Date is >>> %@",anEvent.startDate,anEvent.endDate); 

    } 
} 

을 클릭하고 요구 사항에 따라,의 startDate 및 종료 날짜를 설정합니다.

그래서 원하는 모든 것을 얻을 수 있습니다.

행운을 빕니다.

+0

대단히 감사합니다. 우수한 솔루션이 나를 위해 일했습니다. – sachi

+0

위대한 .....! 환영.. –

관련 문제