我有这个代码从日历应用程序中读取日历数据。
EKEventStore *store = [[EKEventStore alloc] init];
[store requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted,
NSError *error) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Import" message:@"Import Unavailable" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
}];
NSCalendar *calendar = [NSCalendar currentCalendar];
// Create the start date components
NSDateComponents *oneDayAgoComponents = [[NSDateComponents alloc] init];
oneDayAgoComponents.day = -1;
NSDate *oneDayAgo = [calendar dateByAddingComponents:oneDayAgoComponents
toDate:[NSDate date]
options:0];
// Create the end date components
NSDateComponents *oneYearFromNowComponents = [[NSDateComponents alloc] init]; oneYearFromNowComponents.year = 1;
NSDate *oneYearFromNow = [calendar dateByAddingComponents:oneYearFromNowComponents
toDate:[NSDate date]
options:0];
// Create the predicate from the event store's instance method
NSPredicate *predicate = [store predicateForEventsWithStartDate:oneDayAgo
endDate:oneYearFromNow
calendars:nil];
// Fetch all events that match the predicate
NSArray *events = [store eventsMatchingPredicate:predicate];
for (id name in events)
NSLog (@"%@", name);
它记录输出结果的完整细节:
EKEvent <0x937c410>
{ title = Meeting w/ David;
location = (null);
calendar = EKCalendar <0x938a650> {title = Calendar; type = Local; allowsModify = YES; color = #1BADF8;};
alarms = (null);
URL = (null);
lastModified = 2014-03-27 11:52:39 +0000;
timeZone = Asia/Manila (GMT+8) offset 28800
};
location = (null);
startDate = 2014-03-28 04:00:00 +0000;
endDate = 2014-03-28 05:00:00 +0000;
allDay = 0;
floating = 0;
recurrence = (null);
attendees = (null)
};
我想要的是,我只想在3个独立的阵列上获取开始日期,结束日期和位置。我如何获得这些?
答案 0 :(得分:0)
BITTER BOYS :( 继承了我的问题的答案:
将最后一个代码修改为
NSArray *events = [store eventsMatchingPredicate:predicate];
for (id name in events){
NSString *theName = [name valueForKey:@"title"];
NSLog (@"%@", theName);
//NSLog (@"%@", name);
}