我在 Xcode 6.0.1 上,使用 Event Kit 制作一个测试应用程序。以下代码成功填充了每个事件的标题,但即使 hasNotes 属性返回 YES,它的注释也会返回为 (null)。而且,我可以在 iPhone 的默认日历应用中看到同一事件的备注。
我做错了什么?
- (void)viewDidLoad
{
[super viewDidLoad];
[eventStore requestAccessToEntityType:EKEntityTypeEvent
completion:^(BOOL granted, NSError *error) {
dispatch_async(dispatch_get_main_queue(), ^{
if (error)
{
NSLog(@" !! error");
// display error message here
}
else if (!granted)
{
NSLog(@"Not Granted");
// display access denied error message here
}
else
{
// access granted
NSCalendar *calendar = [NSCalendar currentCalendar];
// Create the start date components
NSDateComponents *oneWeekAgoComponents = [[NSDateComponents alloc] init];
oneWeekAgoComponents.day = -1;
NSDate *oneWeekAgo = [calendar dateByAddingComponentsneWeekAgoComponents toDate:[NSDate date] options:0];
// Create the end date components
NSDateComponents *oneMonthFromNowComponents = [[NSDateComponents alloc] init];
oneMonthFromNowComponents.month = 1;
NSDate *oneMonthFromNow = [calendar dateByAddingComponentsneMonthFromNowComponents toDate:[NSDate date] options:0];
// Create the predicate from the event store's instance method
NSPredicate *predicate = [eventStore predicateForEventsWithStartDateneWeekAgo endDateneMonthFromNow calendars:nil];
// Fetch all events that match the predicate
_eventArray = [eventStore eventsMatchingPredicate:predicate];
[self.tableView reloadData];
}
});
}];
}
- (UITableViewCell *)tableViewUITableView *)tableView cellForRowAtIndexPathNSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier"Cell" forIndexPath:indexPath];
EKEvent *event = [self.eventArray objectAtIndex:indexPath.row];
cell.textLabel.text = event.title;
if (event.hasNotes) {
cell.detailTextLabel.text = event.notes;
} else {
cell.detailTextLabel.text = @"";
}
return cell;
}
我还没有完全解决,但有一点线索。
NSArray *events = [eventStore eventsMatchingPredicate:predicate];
这没有得到注释。所以,相反,我通过执行来枚举返回的事件
[eventStore enumerateEventsMatchingPredicate:predicate usingBlock:^(EKEvent *event, BOOL *stop) {
NSLog(@"title: %@",event.title);
NSLog(@"hasNotes: %s",event.hasNotes ? "YES":"NO");
NSLog(@"notes: %@",event.notes);
NSLog(@"-----");
[_eventTitles addObject:event.title];
[_eventTitles addObject:event.hasNotes ? event.notes : @""];
}];
这个返回实际的笔记(null)。
关于ios - 即使 EKEvent.hasNotes 返回 YES,EKEvent.notes 也会返回 (null),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26052460/
欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) | Powered by Discuz! X3.4 |