我正在向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