-3
我想问一下如果可能,怎么做。 你可以给我一些示例代码或片段如何做到这一点?谢谢。如何从我的iphone日历中检索事件?
我想问一下如果可能,怎么做。 你可以给我一些示例代码或片段如何做到这一点?谢谢。如何从我的iphone日历中检索事件?
你想看看Event Kit,它有示例代码以及有关阅读日历事件的文档。
获取所有事件的代码。有关更多信息,可以使用上述Event Kit苹果文档。
NSDate *start = ...
NSDate *finish = ...
// use Dictionary for remove duplicates produced by events covered more one year segment
NSMutableDictionary *eventsDict = [NSMutableDictionary dictionaryWithCapacity:1024];
NSDate* currentStart = [NSDate dateWithTimeInterval:0 sinceDate:start];
int seconds_in_year = 60*60*24*365;
// enumerate events by one year segment because iOS do not support predicate longer than 4 year !
while ([currentStart compare:finish] == NSOrderedAscending) {
NSDate* currentFinish = [NSDate dateWithTimeInterval:seconds_in_year sinceDate:currentStart];
if ([currentFinish compare:finish] == NSOrderedDescending) {
currentFinish = [NSDate dateWithTimeInterval:0 sinceDate:finish];
}
NSPredicate *predicate = [eventStore predicateForEventsWithStartDate:currentStart endDate:currentFinish calendars:nil];
[eventStore enumerateEventsMatchingPredicate:predicate
usingBlock:^(EKEvent *event, BOOL *stop) {
if (event) {
[eventsDict setObject:event forKey:event.eventIdentifier];
}
}];
currentStart = [NSDate dateWithTimeInterval:(seconds_in_year + 1) sinceDate:currentStart];
}
NSArray *events = [eventsDict allValues];
当在这里提问时,如果您首先自己做了一些基础研究,那么您会得到更好的答复。在这里提出问题不应该是您尝试的第一件事。 – jrturton