1
그래서 캘린더에서 현재 이벤트를 가져와야합니다. I.E - 아직 시작하지 못했던 이벤트. 일부 코드를 작성했지만 작동하지 않습니다. 디버깅을 통해 oneDayAgo 변수가 0 인 것으로 파악되어 그 이유를 알 수 없습니다. oneWeekFromNow 변수가 유용합니다.EKEvent 현재 이벤트 가져 오기 iOS7
-(void)getCurrentEvent{
// Get appropriate calendar
[self.store requestAccessToEntityType:EKEntityTypeEvent
completion:^(BOOL granted, NSError *error) {
NSCalendar *calendar = [NSCalendar currentCalendar];
NSDateComponents *oneDayAgoComponents = [[NSDateComponents alloc] init];
oneDayAgoComponents.day -=1;
NSDate *oneDayAgo = [calendar dateByAddingComponents:oneDayAgoComponents
toDate:[NSDate date]
options:0];
NSDateComponents *oneWeekFromNowComponents = [[NSDateComponents alloc] init];
oneWeekFromNowComponents.week = 1;
NSDate *oneWeekFromNow = [calendar dateByAddingComponents:oneWeekFromNowComponents
toDate:[NSDate date]
options:0];
NSPredicate *predicate = [self.store predicateForEventsWithStartDate:oneDayAgo
endDate:oneWeekFromNow
calendars:nil];
NSMutableArray *currentEvens = [[NSMutableArray alloc]init];
// Fetch all events that match the predicate
[self.store enumerateEventsMatchingPredicate:predicate usingBlock:^(EKEvent *event, BOOL *stop) {
if (([event.startDate compare:[NSDate date]] == NSOrderedDescending) &&
([[NSDate date] compare:event.endDate] == NSOrderedDescending)) {
[currentEvens addObject:event];
}
}];
self.lblEvent.text = [NSString stringWithFormat:@"%@", currentEvens];
[self.view reloadInputViews];
}];
}
감사합니다! 그 오타를 알아 채지 못했습니다. 어리석은 실수 ... 잘 보아라. * –
@MichalShatz 즐거움 :-) 나는 "에스프레소 한잔"을 먹은 직후 "시기 적절한"질문이었다. – Unheilig