无法在iOS中创建提醒日历

时间:2012-10-25 17:02:49

标签: iphone ios objective-c xcode calendar

我正在尝试创建提醒日历,以便添加和删除提醒。它实际上在我使用的设备(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 个答案:

答案 0 :(得分: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;
        }
    }

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

答案 1 :(得分:2)

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

第二:你在使用iOS6吗?只有从iOS6开始提醒(在EventKit中):link

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

您可以尝试的第一件事是循环所有来源,直到找到合适的来源。 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];
}

试着让我知道

答案 2 :(得分:0)

解决了我的问题的原因是不将日历保存到本地源,而是保存到EKSourceTypeCalDAV(iCloud)。它有效,并且它在所有设备上同步。

答案 3 :(得分: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)