我有一个应用程序,通过按钮提醒患者他/她的约会。 如果病人点击了按钮,我想要提取患者日历中的所有事件以检查约会是否已经存在。如果不存在,我会创建活动。以开始日期获取iPhone日历中的所有事件
我知道如何将事件添加到日历中,但取回是返回零计数?
下面是我的代码:
//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 ..
任何答复pleeeeease? – 2013-04-11 11:41:57