gpt4 book ai didi

macos - 在 OS X 上创建时出现 EKReminder 错误 : No calendar has been set

转载 作者:行者123 更新时间:2023-12-02 03:37:56 26 4
gpt4 key购买 nike

我有一段代码尝试使用 OS X 10.8 及更高版本中的 EventKit 框架保存通用提醒。这是我的代码片段:

NSLog(@"Creating reminder.");
EKEventStore *eventStore = [[EKEventStore alloc] initWithAccessToEntityTypes:EKEntityMaskReminder];
NSLog(@"Auth status: %lu", [EKEventStore authorizationStatusForEntityType:EKEntityTypeReminder]);

[eventStore requestAccessToEntityType:EKEntityTypeReminder completion:^(BOOL granted, NSError *error) {
NSLog(@"Granted: %d Error: %@", granted, error);
if (granted) {
EKReminder *reminder = [EKReminder reminderWithEventStore:eventStore];
reminder.title = @"My Reminder";
EKCalendar *reminderCalendar = [EKCalendar calendarForEntityType:EKEntityTypeReminder eventStore:eventStore];
NSLog(@"Using EKCalendar: %@", reminderCalendar);
reminder.calendar = reminderCalendar;

NSError *commitError = nil;
if (![eventStore saveReminder:reminder commit:YES error:&commitError] || commitError) {
NSLog(@"An error occurred committing the reminder: %@", commitError);
} else {
NSLog(@"Reminder created successfully.");
}
}
}];

这是我看到的输出:

2014-01-08 19:56:21.182 MyApp[6073:303] Creating reminder.
2014-01-08 19:56:21.358 MyApp[6073:303] Auth status: 3
2014-01-08 19:56:21.358 MyApp[6073:3423] Granted: 1 Error: (null)
2014-01-08 19:56:21.359 MyApp[6073:3423] Using EKCalendar: EKCalendar <0x9c430>, calendarIdentifier:9BD66DA9-014D-4918-849A-1D6763994511, allowEvents:0, allowReminders:1, allowsContentModifications:1, isSubscribed:0, isDeletable:1, isRenameable:1, isShareable:0, defaultOrganizerIsMeForNewItems:0
2014-01-08 19:56:21.366 MyApp[6073:3423] An error occurred committing the reminder: Error Domain=EKErrorDomain Code=1 "No calendar has been set." UserInfo=0x60000067d900 {NSLocalizedDescription=No calendar has been set.}

但是,尽管出现错误消息,EKCalendar 已成功创建/访问,EKReminder 对象上进行设置。

我发现的唯一其他类似资源是在 iOS 上使用 EventKit 时发生的,其中获取访问权限的方法略有不同。

根据此 Apple 文档:https://developer.apple.com/library/ios/documentation/DataManagement/Conceptual/EventKitProgGuide/ReadingAndWritingReminders/ReadingAndWritingReminders.html

You can create reminders using the reminderWithEventStore: class method. The title and calendar properties are required. The calendar for a reminder is the list with which it is grouped.

但我一定做错了什么。在我的 App Sandbox/App Data 权限下,为了安全起见,我选择了 CalendarContacts,但该错误似乎与权限无关。

最佳答案

而不是使用:

EKCalendar *reminderCalendar = [EKCalendar calendarForEntityType:EKEntityTypeReminder eventStore:eventStore];
NSLog(@"Using EKCalendar: %@", reminderCalendar);
reminder.calendar = reminderCalendar;

我能够使用以下方法成功创建 EKReminder:

reminder.calendar = [eventStore defaultCalendarForNewReminders];

关于macos - 在 OS X 上创建时出现 EKReminder 错误 : No calendar has been set,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21009825/

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