我有应用程序通过按钮提醒患者他/她的预约。如果患者单击按钮,我想获取患者日历中的所有事件以检查约会是否已经存在。如果不存在,我将创建事件。
我知道如何将事件添加到日历中,但获取是返回零计数?
下面是我的代码:
//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 *AppointmentTitle=@"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 个月前运行良好。突然,当我回来测试它时,它不起作用。我错过了什么?或者我的代码有什么错误吗?
我需要你的帮助。。