无法在iOS中创建提醒日历

typ*_*tch 10 iphone xcode calendar objective-c ios

我正在尝试创建提醒日历,以便添加和删除提醒.它实际上在我使用的设备(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.
Run Code Online (Sandbox Code Playgroud)

在大多数情况下工作,这出现在一些设备上 -

Error Domain=EKErrorDomain Code=24 “That account does not support reminders.” 
Run Code Online (Sandbox Code Playgroud)

权限在"设置","隐私","提醒"下授予和检查.我在文档中找不到有关您遇到此错误的条件的任何内容.

谢谢!

Wal*_*ena 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;
        }
    }
Run Code Online (Sandbox Code Playgroud)

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


Lom*_*baX 2

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

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

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

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

typedef enum {
   EKSourceTypeLocal,
   EKSourceTypeExchange,
   EKSourceTypeCalDAV,
   EKSourceTypeMobileMe,
   EKSourceTypeSubscribed,
   EKSourceTypeBirthdays
} EKSourceType;
Run Code Online (Sandbox Code Playgroud)

找到一个合适的:

// 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;
    }
}
Run Code Online (Sandbox Code Playgroud)

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

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];
}
Run Code Online (Sandbox Code Playgroud)

尝试让我知道