在这里遇到一个非常奇怪的问题,在我看来这是EventKit API的一个问题,我只是想检查一下我没做什么。
测试案例1:
测试案例2:
测试案例3:
我是疯了还是这是API的错误?
干杯!
以下是代码:
EKCalendar *remindersList = nil;
NSString *remindersListIdent = [[NSUserDefaults standardUserDefaults] objectForKey:kReminderListIdentDefaultsKey];
if(remindersListIdent) {
remindersList = [store calendarWithIdentifier:remindersListIdent];
if(remindersList) {
// has valid reminders list so save reminder and return (don't run rest of function)
[self saveReminder:reminder toCalendar:remindersList withTypeLabel:reminderTypeLabel];
return;
}
}
NSArray *currentCalendars = [store calendarsForEntityType:EKEntityTypeReminder];
for(EKCalendar *cal in currentCalendars) {
if([[cal title] isEqualToString:@"My App Name"]) {
remindersList = cal;
[[NSUserDefaults standardUserDefaults] setObject:[remindersList calendarIdentifier] forKey:kReminderListIdentDefaultsKey];
[[NSUserDefaults standardUserDefaults] synchronize];
[self saveReminder:reminder toCalendar:remindersList withTypeLabel:reminderTypeLabel];
return;
}
}
EKSource *localSource = nil;
for (EKSource *source in store.sources) {
if (source.sourceType == EKSourceTypeCalDAV && [source.title isEqualToString:@"iCloud"]) {
localSource = source;
break;
}
}
if(localSource) {
remindersList = [self newCalendarListInSource:localSource];
}
if(!remindersList) {
for (EKSource *source in store.sources) {
if (source.sourceType == EKSourceTypeLocal) {
localSource = source;
remindersList = [self newCalendarListInSource:localSource];
if(remindersList) {
break;
}
}
}
}
if(!remindersList) {
dispatch_async(dispatch_get_main_queue(), ^{
// show error message
});
}
else {
[[NSUserDefaults standardUserDefaults] setObject:[remindersList calendarIdentifier] forKey:kReminderListIdentDefaultsKey];
[[NSUserDefaults standardUserDefaults] synchronize];
[self saveReminder:reminder toCalendar:remindersList withTypeLabel:reminderTypeLabel];
}
这是newCalendarListInSource的内容:
EKCalendar *remindersList;
remindersList = [EKCalendar calendarForEntityType:EKEntityTypeReminder eventStore:store];
remindersList.source = localSource;
[remindersList setTitle:@"My App Name"];
NSError *listCreateError = nil;
[store saveCalendar:remindersList commit:YES error:&listCreateError];
if(!listCreateError) {
return remindersList;
}
else {
NSLog(@"Failed to create reminders list with error: %@", [listCreateError localizedDescription]);
答案 0 :(得分:-1)
对于所有仍有问题的人,请检查手机中是否存在您使用的EKSourceType
。对于Swift,请尝试使用EKSourceType.Exchange
。请注意,我的Outlook / Exchange帐户已同步到我的手机。
我知道这很模糊,但当我使用EKSourceType.Exchange
时,它对我有用。 (玩它)