【发布时间】:2013-03-19 22:50:00
【问题描述】:
我正在开发一个日历应用程序。
在一个月的时间里,我整天都在循环以获取当天的事件。我必须这样做才能处理重复发生的事件和超过一天的事件。
除了一种情况外,它工作得很好:为期数天的活动的最后一天。我看到了这个事件的其他日子的事件,但没有看到最后一个事件。 (我在 GMT+1 时区,这就是我有这个时间的原因)
SEARCH FOR THE LAST DAY OF EVENT
Start: 2013-03-25 23:00:00 +0000
End: 2013-03-26 22:59:59 +0000
EVENT
Start: 2013-03-24 21:00:06 +0000
End: 2013-03-26 21:00:06 +0000
No results!
这是返回当天事件的方法:
+ (NSArray *)ekEventsWithStartDate:(NSDate*)startDate endDate:(NSDate*)endDate
{
NSLog(@"ekEventsWithStartDate:%@ endDate:%@",startDate,endDate);
NSPredicate *predicate = [_eventStore predicateForEventsWithStartDate:startDate
endDate:endDate
calendars:nil];
NSArray *events = [_eventStore eventsMatchingPredicate:predicate];
NSLog(@"events (%d):%@",[events count],events);
return events;
}
以下是活动详情:
EKEvent <0xb0635e0> {EKEvent <0xb0635e0>
{title = 24-26 Mars 10 PM;
location = ;
calendar = EKCalendar <0xb3c3c80> {title = Calendar; type = Local; allowsModify = YES; color = #0E61B9;};
alarms = (null);
URL = (null);
lastModified = 2013-03-19 22:11:10 +0000;
timeZone = Europe/Paris (GMT+01:00) offset 3600};
location = ;
startDate = 2013-03-24 21:00:06 +0000;
endDate = 2013-03-26 21:00:06 +0000;
allDay = 0;
floating = 0;
recurrence = (null);
attendees = (null)}
这是来自 ekEventsWithStartDate 方法的该事件 3 天的日志:
ekEventsWithStartDate:2013-03-23 23:00:00 +0000 endDate:2013-03-24 22:59:59 +0000
events (1):(
"EKEvent <0x9b44c00> {EKEvent <0x9b44c00> {title = 24-26 Mars 10 PM; location = ; calendar = EKCalendar <0xb336870> {title = Calendar; type = Local; allowsModify = YES; color = #0E61B9;}; alarms = (null); URL = (null); lastModified = 2013-03-19 22:11:10 +0000; timeZone = Europe/Paris (GMT+01:00) offset 3600}; location = ; startDate = 2013-03-24 21:00:06 +0000; endDate = 2013-03-26 21:00:06 +0000; allDay = 0; floating = 0; recurrence = (null); attendees = (null)}"
)
ekEventsWithStartDate:2013-03-24 23:00:00 +0000 endDate:2013-03-25 22:59:59 +0000
events (1):(
"EKEvent <0xb28b970> {EKEvent <0xb28b970> {title = 24-26 Mars 10 PM; location = ; calendar = EKCalendar <0xb336870> {title = Calendar; type = Local; allowsModify = YES; color = #0E61B9;}; alarms = (null); URL = (null); lastModified = 2013-03-19 22:11:10 +0000; timeZone = Europe/Paris (GMT+01:00) offset 3600}; location = ; startDate = 2013-03-24 21:00:06 +0000; endDate = 2013-03-26 21:00:06 +0000; allDay = 0; floating = 0; recurrence = (null); attendees = (null)}"
)
ekEventsWithStartDate:2013-03-25 23:00:00 +0000 endDate:2013-03-26 22:59:59 +0000
events (0):(null)
为什么方法返回空数组?
辅助问题:有没有更好的方法来获取一个月中每一天的事件?我正在寻找更好的表现。
感谢您的帮助!
2013 年 3 月 20 日编辑: 多亏了 Dhruvik,我发现我的代码在 iOS 5.X 上完美运行,但在 iOS 6.X 上却不行(4.X 没有测试)。
我检查了 5.X 和 6.X 版本的事件和日期,我看到的唯一区别是事件日历时区属性:
iOS 5.X
timeZone = Europe/Paris (CET)
iOS 6.X
timeZone = Europe/Paris (UTC+01:00)
此问题与全天活动无关。
iOS 6.X 有同样的问题吗?
【问题讨论】:
标签: iphone ios objective-c ekeventkit