2012-12-11 48 views
1

我在EKCalendar中的EKCalendar中保存了28個EKEvent,日期範圍爲2012-01-01和2013-01-18,EKEvent全部存儲,我可以看到它在iCloud上的iOS日曆,然後我想找回這一切EKEvent範圍2012-01-01和2013年1月18日我用EKEventStore的這種方法:predicateForEventsWithStartDate:endDate:日曆:EKEventStore不起作用

predicateForEventsWithStartDate:endDate:calendars: 

是在NSPredicate來獲取事件日曆,我通過開始日期2012-01-01和endDate:2013-01-18所以返回我與EKEvent的數組只有8個元素,所以我的問題是爲什麼它沒有找到我所有的28事件?我錯了什麼?

編輯:

這是完整的代碼我使用:

NSDate* sourceDate2 = [dateFormat dateFromString:@"2012/01/01"]; 


    NSTimeZone* sourceTimeZone2 = [NSTimeZone timeZoneWithAbbreviation:@"GMT"]; 
    NSTimeZone* destinationTimeZone2 = [NSTimeZone systemTimeZone]; 

    NSInteger sourceGMTOffset2 = [sourceTimeZone2 secondsFromGMTForDate:sourceDate2]; 
    NSInteger destinationGMTOffset2 = [destinationTimeZone2 secondsFromGMTForDate:sourceDate2]; 
    NSTimeInterval interval2 = destinationGMTOffset2 - sourceGMTOffset2; 

    NSDate* destinationDate2 = [[NSDate alloc] initWithTimeInterval:interval2 sinceDate:sourceDate2]; 

    NSTimeInterval time2 = floor([destinationDate2 timeIntervalSinceReferenceDate]/86400.0) * 86400.0; 

    NSDate *startDate = [NSDate dateWithTimeIntervalSinceReferenceDate:time2]; 

然後我使用相同的代碼創建的2013年1月18日日期是在結束日期,那麼我這樣做:

EKEventStore *eventStore = [[EKEventStore alloc] init]; 

NSPredicate *predicateEvent = [eventStore predicateForEventsWithStartDate:startDate endDate:endDate calendars:[eventStore calendarsForEntityType:EKEntityTypeEvent]]; 

NSArray *eventArray = [eventStore eventsMatchingPredicate:predicateEvent]; 

eventArray只包含8個元素......其他20個在哪裏?請我瘋了別人能幫助我嗎?

+0

是在同一個'EKCalendar'中的28'EVEvent's?你可以發佈完整的代碼,試圖獲取你的'EKEvent'嗎? – holex

+0

是在同一個日曆中... – Piero

+0

你能顯示你的代碼嗎? – holex

回答

2

在您的設備上,請轉到:Settings > Mail, Contacts, Calendars,並在Calendars子部分轉到Sync > All Events。不只是過去30天,60天等事件。

+0

感謝您的答案,我還沒有嘗試過,如果您的解決方案的工作,但我有一個問題,如果我在應用程序商店發佈我的應用程序,我不能去每個用戶設備,並更改該選項:) – Piero

+0

這就是爲什麼你應該有一個幫助部分....... – jhilgert00