我正在向IOS日历添加事件数组。因为它必须单击按钮才会发起攻击。通过这样做,所有事件都会一次又一次地添加。所以过度过来,我用NSPredicate得到所有的事件,并做验证像下面检查重复事件,但不在IOS中的事件存储区中获取所有事件
NSDate *edate=[formatter dateFromString:startDateString];
NSDate *fdate=[formatter dateFromString:endDateString];
NSLog(@"Start Date is %@",edate);
NSLog(@"End Date is %@",fdate);
event1.startDate =edate;
event1.endDate=fdate;
NSArray *caleandarsArray = [[NSArray alloc] init];
caleandarsArray = [eventStore calendars] ;
NSPredicate *predicateForEvents = [eventStore predicateForEventsWithStartDate:edate endDate:fdate calendars:caleandarsArray]; // nil will search through all calendars
NSArray *eventsOnDate = [eventStore eventsMatchingPredicate:predicateForEvents];
NSLog(@"Events on holday date is %@",eventsOnDate);
BOOL eventExists = NO;
for (EKEvent *eventToCheck in eventsOnDate)
{
NSLog(@" eventToCheck title is %@",eventToCheck.title);
NSLog(@" myTripsArray title is %@",[myTripsArray objectAtIndex:i]);
if ([eventToCheck.title isEqualToString:[myTripsArray objectAtIndex:i]])
{
eventExists = YES;
NSLog(@"Event already existed");
}
}
if (eventExists == NO)
{
[event1 setTimeZone:[NSTimeZone systemTimeZone]];
[event1 setCalendar:[eventStore defaultCalendarForNewEvents]];
NSError *err;
if(err)
{
NSLog(@"Error occured");
}
else
{
NSLog(@"Error not occured");
}
[eventStore saveEvent:event1 span:EKSpanThisEvent error:&err];
}
}
通过上面的代码,我只得到了生日事件不被存在的任何其他活动。如何从日历中获取所有事件。
请帮我解决我出错的地方。
没有猪头...它没有帮助.. – iSwaroop
“EKEvent {\ n \ t EKEvent <0xd2be4f0> \ n {\ t title = \ t \ tLaxman Rajana \ U2019s Bir thday; \ n \ t location = \ t(null); \ n \ t calendar = \ tEKCalendar <0xd2b7b80> {title = Birthdays; type = Birthday; allowsModify = NO; color =#8295AF;}; \ n \ t警报= \ t \ t(null); \ n \ t URL = \ t \ t \ t(null); \ n \ t lastModified =(null); \ n \ t timeZone = \ t(null)\ n}; \ n \ t location = \ t(null); \ n \ t startDate = \ t2013-10-20 18:30:00; \ n \ t endDate = \ t \ t2013-10-21 18:29:59; \ n \ t allDay = \ t \ t1; \ n \ t floating = \ t1; \ n \ t recurrence = \ tEKRecurrenceRule <0x12a36f90> RRULE FREQ = YEARLY; INTERVAL = 1; \ n \ t参加者= \ t(null)\ n}; – iSwaroop