Lof*_*ens 5 xcode calendar ios ios5 ios6
我已经创建了一个包含一些事件的日历,现在我想从该日历中获取所有事件,而不知道他们的开始日期或结束日期是什么.
我尝试过的代码,从所有日历中获取所有事件,因此我可以稍后按日历ID将它们分开..:
NSPredicate *fetchCalendarEvents = [eventStore predicateForEventsWithStartDate:[NSDate distantPast] endDate:[NSDate distantFuture] calendars:eventStore.calendars];
NSArray *allEvents = [eventStore eventsMatchingPredicate:fetchCalendarEvents];
Run Code Online (Sandbox Code Playgroud)
当数据库清楚地显示日历中的事件时,这会allEvents返回nil.
有人可以帮帮我吗?
我现在有工作.
这是我正在使用的代码:
NSDate* endDate = [NSDate dateWithTimeIntervalSinceNow:[[NSDate distantFuture] timeIntervalSinceReferenceDate]];
NSArray *calendarArray = [NSArray arrayWithObject:cal];
NSPredicate *fetchCalendarEvents = [eventStore predicateForEventsWithStartDate:[NSDate date] endDate:endDate calendars:calendarArray];
NSArray *eventList = [eventStore eventsMatchingPredicate:fetchCalendarEvents];
for(int i=0; i < eventList.count; i++){
NSLog(@"Event Title:%@", [[eventList objectAtIndex:i] title]);
}
Run Code Online (Sandbox Code Playgroud)
从您调用方法的正确日期开始,我将使用我正在使用的日历中的所有事件.
我认为给予[NSDate distantPast]不会起作用,因为它已经过去或者某种东西......设置你的startDate [NSDate date]会起作用.
希望这可以帮助那些有同样问题的人.
| 归档时间: |
|
| 查看次数: |
8037 次 |
| 最近记录: |