xcode 无法在 iOS 中创建提醒日历
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13073634/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Can't create reminder calendar in iOS
提问by typemismatch
I'm trying to create a reminder calendar so I can add and delete reminders. It is actually working well on the devices I use (iPhone 5/4S/4) but on certain client devices which are still iPhones - I'm getting this error below about the account not supporting reminders.
我正在尝试创建一个提醒日历,以便我可以添加和删除提醒。它实际上在我使用的设备(iPhone 5/4S/4)上运行良好,但在某些仍然是 iPhone 的客户端设备上 - 我在下面收到此错误消息,该错误是关于帐户不支持提醒的。
Here is the workflow:
这是工作流程:
* 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.
Works most of the time, this appears on some devices -
大多数时间都可以工作,这会出现在某些设备上 -
Error Domain=EKErrorDomain Code=24 “That account does not support reminders.”
Permissions are granted and checked under Settings, Privacy, Reminders. I can't find anything in the docs about the conditions under which you'd get this error.
在设置、隐私、提醒下授予和检查权限。我在文档中找不到任何关于您收到此错误的条件的信息。
Thanks!
谢谢!
回答by Walter Martin Vargas-Pena
Not sure if you still need this but here is what i ran into.
不确定你是否仍然需要这个,但这是我遇到的。
First of all i'm pretty sure that reminders cannot be set on a calendar with a local source. I kept getting the "That account does not support reminders". Even after setting all non read only properties on the calendar before committing to the event store it still didn't work. The source needs to be calDav. Then I tried Devfly's response and it didn't work either but for a different reason. It kept fetching my gmail calendar which does not allow setting reminders (i think its actually read only for events and reminders). So i used the following code to get the actual iCloud source
首先,我很确定不能在具有本地来源的日历上设置提醒。我一直收到“该帐户不支持提醒”。即使在提交到事件存储之前在日历上设置了所有非只读属性后,它仍然无法正常工作。来源需要是calDav。然后我尝试了 Devfly 的响应,它也不起作用,但出于不同的原因。它一直在获取我的不允许设置提醒的 gmail 日历(我认为它实际上只针对事件和提醒读取)。所以我使用以下代码来获取实际的 iCloud 源
for (EKSource *source in sources) {
NSLog(@"source %@",source.title);
if (source.sourceType == EKSourceTypeCalDAV && [source.title isEqualToString:@"iCloud"]) {
localSource = source;
break;
}
}
This setting this source on my new reminders calendar worked for me. hope it helps someone
在我的新提醒日历上设置此来源对我有用。希望它可以帮助某人
回答by LombaX
First, just a check: you are creating a "new calendar" (a whole calendar), not just a "new reminder", right?
首先,检查一下:您正在创建“新日历”(整个日历),而不仅仅是“新提醒”,对吗?
Second: are you using iOS6? Reminders are available (in EventKit) only starting from iOS6: link
第二:你用的是iOS6吗?提醒可用(在 EventKit 中)仅从 iOS6 开始:链接
As commented by Jesse Rusak, this happens because you are probably creating the new calendar inside an account/source that doesn't support reminders. How do you create the new calendar? Do you set the source property?
正如 Jesse Rusak 评论的那样,发生这种情况是因为您可能正在不支持提醒的帐户/来源中创建新日历。你如何创建新日历?你设置了源属性吗?
the first thing you can try, is to loop all sources until you find a suitable one. EKSourceTypeLocal supports reminders. iCal too. Here a list of EKSourceType
您可以尝试的第一件事是循环所有来源,直到找到合适的来源。EKSourceTypeLocal 支持提醒。iCal 也是。这里是 EKSourceType 的列表
typedef enum {
EKSourceTypeLocal,
EKSourceTypeExchange,
EKSourceTypeCalDAV,
EKSourceTypeMobileMe,
EKSourceTypeSubscribed,
EKSourceTypeBirthdays
} EKSourceType;
Find a suitable one:
找一个合适的:
// 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;
}
}
Then, create the new calendar setting the right source
然后,创建新的日历设置正确的来源
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];
}
Try and let me know
尝试让我知道
回答by Devfly
What solved my problem is not saving the calendar to the local source, but instead to EKSourceTypeCalDAV
(iCloud). It works, and it's synced across all devices.
解决我的问题的不是将日历保存到本地源,而是保存到EKSourceTypeCalDAV
(iCloud)。它可以工作,并且可以在所有设备上同步。
回答by jrc
The local store may not support reminders. This is reproducible if iCloud is enabled.
本地商店可能不支持提醒。如果启用了 iCloud,这是可重现的。
This is the most reliable solution I could find, without hard-coding any assumptions:
这是我能找到的最可靠的解决方案,无需硬编码任何假设:
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)