3

Hitting a very strange issue here, which seems to me to be an issue with the EventKit API and I just want to check it's nothing I'm doing.

Test case 1:

  • Reminders are enabled in Privacy for the app
  • The device has an iCloud account, but it's set to not sync reminders
  • I can create a local reminders list in the 'Reminders' app from Apple
  • ISSUE - Trying to create a new calendar of entity type EKEntityTypeReminder with a source of type EKSourceTypeLocal fails

Test case 2:

  • Reminders are enabled in Privacy for the app
  • The device has no iCloud account
  • I can create a local reminders list in the 'Reminders' app from Apple
  • I can create a local reminders list via the EK API

Test case 3:

  • Reminders are enabled in Privacy for the app
  • The device has an iCloud account and is set to sync reminders
  • I can create an iCloud reminders list in the 'Reminders' app from Apple
  • I can create an iCloud reminders list via the EK API

Am I going crazy or is this a bug with the API?

Cheers!

Here's the code:

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];
}

And this is the contents of 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]);
4

1 回答 1

-1

对于所有对此仍有疑问的人,请检查您EKSourceType使用的手机是否存在。对于 Swift,请尝试使用EKSourceType.Exchange. 请注意,我有一个 Outlook/Exchange 帐户同步到我的手机。

我知道这很模糊,但是当我使用 时EKSourceType.Exchange,它对我有用。(玩它)

于 2016-07-07T02:15:01.413 回答