gpt4 book ai didi

ios - 即使 EKEvent.hasNotes 返回 YES,EKEvent.notes 也会返回 (null)

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:03:47 28 4
gpt4 key购买 nike

我正在使用 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 dateByAddingComponents:oneWeekAgoComponents toDate:[NSDate date] options:0];
// Create the end date components
NSDateComponents *oneMonthFromNowComponents = [[NSDateComponents alloc] init];
oneMonthFromNowComponents.month = 1;
NSDate *oneMonthFromNow = [calendar dateByAddingComponents:oneMonthFromNowComponents toDate:[NSDate date] options:0];

// Create the predicate from the event store's instance method
NSPredicate *predicate = [eventStore predicateForEventsWithStartDate:oneWeekAgo endDate:oneMonthFromNow calendars:nil];
// Fetch all events that match the predicate
_eventArray = [eventStore eventsMatchingPredicate:predicate];

[self.tableView reloadData];

}
});
}];
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)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 : @""];
}];

这个返回实际的笔记(空)。

关于ios - 即使 EKEvent.hasNotes 返回 YES,EKEvent.notes 也会返回 (null),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26052460/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com