10

我正在尝试创建一个提醒日历,以便添加和删除提醒。它实际上在我使用的设备(iPhone 5/4S/4)上运行良好,但在某些仍然是 iPhone 的客户端设备上 - 我在下面收到关于该帐户不支持提醒的错误。

这是工作流程:

* Init the event store.
* Request permission (check its granted for Reminder types) (iOS6+) for lower we just init.
* Create a new calendar, local storage, type = Reminder
* Save calendar to get its Identifier.

大部分时间都有效,这出现在某些设备上 -

Error Domain=EKErrorDomain Code=24 “That account does not support reminders.” 

在设置、隐私、提醒下授予和检查权限。我在文档中找不到任何关于您会收到此错误的条件的信息。

谢谢!

4

4 回答 4

5

不知道你是否还需要这个,但这是我遇到的。

首先,我很确定不能在具有本地来源的日历上设置提醒。我不断收到“该帐户不支持提醒”。即使在提交到事件存储之前在日历上设置了所有非只读属性之后,它仍然无法正常工作。来源需要是 calDav。然后我尝试了 Devfly 的响应,它也没有工作,但出于不同的原因。它一直在获取我的 gmail 日历,它不允许设置提醒(我认为它实际上只用于事件和提醒)。所以我使用下面的代码来获取实际的 iCloud 源

    for (EKSource *source in sources) {
        NSLog(@"source %@",source.title);
        if (source.sourceType ==  EKSourceTypeCalDAV && [source.title isEqualToString:@"iCloud"]) {
            localSource = source;
            break;
        }
    }

在我的新提醒日历上设置此来源对我有用。希望它可以帮助某人

于 2013-05-21T16:37:55.400 回答
2

首先,只是检查一下:您正在创建一个“新日历”(整个日历),而不仅仅是一个“新提醒”,对吧?

第二:你用的是iOS6吗?提醒(在 EventKit 中)仅从 iOS6 开始可用:链接

正如 Jesse Rusak 评论的那样,发生这种情况是因为您可能在不支持提醒的帐户/源中创建新日历。您如何创建新日历?你设置源属性吗?

您可以尝试的第一件事是循环所有来源,直到找到合适的来源。EKSourceTypeLocal 支持提醒。iCal 也是。这里是 EKSourceType 的列表

typedef enum {
   EKSourceTypeLocal,
   EKSourceTypeExchange,
   EKSourceTypeCalDAV,
   EKSourceTypeMobileMe,
   EKSourceTypeSubscribed,
   EKSourceTypeBirthdays
} EKSourceType;

找一个合适的:

// find local source for example
EKSource *localSource = nil;
for (EKSource *source in store.sources)
{
    if (source.sourceType == EKSourceTypeLocal)  // or another source type that supports
    {
        localSource = source;
        break;
    }
}

然后,创建新的日历设置正确的来源

EKCalendar *cal;
if (identifier == nil)
{
    cal = [EKCalendar calendarForEntityType:EKEntityTypeReminder eventStore:store];
    cal.title = @"Demo calendar";
    cal.source = localSource;
    [store saveCalendar:cal commit:YES error:nil];
}

试着让我知道

于 2013-04-28T20:32:20.393 回答
0

解决我的问题的方法不是将日历保存到本地源,而是保存到EKSourceTypeCalDAV(iCloud)。它可以工作,并且可以在所有设备上同步。

于 2013-05-02T13:28:01.407 回答
0

本地商店可能不支持提醒。如果启用了 iCloud,这是可以重现的。

这是我能找到的最可靠的解决方案,无需硬编码任何假设:

    let calendar = EKCalendar(forEntityType: .Reminder, eventStore: eventStore)

    if eventStore.sources.count == 0 { // reproducible after Reset Content and Settings
        calendar.source = EKSource()
    }
    else {
        calendar.source = eventStore.defaultCalendarForNewReminders().source
    }

    eventStore.saveCalendar(calendar, commit: true)
于 2015-10-02T17:04:48.607 回答