如何确定默认EKCalendar“日历”是否可以隐藏?(How to decide whether

2019-07-29 08:42发布

I'm writing an app that deals with calendars. In the app I'm displaying a list of all available calendars for the user to enable or disable. I'm not using the EventKitUI framework for purposes of my own design and UI.

I get a neat list of calendars by polling the calendars property of an EKEventStore object. On my device, however, there's an EKCalendar object in that list that is not shown by the EKEventKitUI. This is a description of the object in the debugger:

EKCalendar <0xcea6b60> {title = Agenda; type = Local; allowsModify = YES; color = #711A76;}

I'm running my iPhone in Dutch, which is why the title is 'Agenda' and not 'Calendar', but if you run the iPhone in English that's what you'll see. It looks like this is iOS' default calendar, but since I have all my calendars set up to sync with iCloud, it's disabled for the built in calendar apps. I want to disable it in my own app too, but I don't know how.

From looking at the properties of EKCalendar I cannot discern one for deciding which calendar I should 'hide'. There's the type property that is 'Local' for this default calendar, but if someone is not using iCloud I imagine all the calendars are of a local type. subscription is not it either, nor is allowsContentModifications. I've seen examples of people hiding the default calendar based on it's title, but as you can see, the title is localized and thus very impractical, that just feels wrong.

What's the trick to decide which calendar is the default calendar and whether to hide it or not, in order to parallel the list of calendars that your regular iCal/Calendar app displays?

EDIT: Although the question was marked as answered, the answer contains a big "no, you can't". I've solved this issue for my users by adding a settings panel switch to 'hide local calendars', but it's a very, very unelegant solution.

Answer 1:

要回答粗体你的问题,没有一个神奇的属性,你可以用它来确定是否应日历被隐藏或显示。

但是,如果你的理论是关于日历应用程序隐藏“本地”日历正确的,如果其他日历类型可供选择(的iCloud / MobileMe的,交易所的CalDAV等),那么你就可以反映其逻辑中使用的代码EKSource在阵列EKEventStore

EKEventStore *store = [[EKEventStore alloc] init];

for (EKSource *source in store.sources)
    if (source.sourceType == EKSourceTypeExchange || source.sourceType == EKSourceTypeCalDAV)
    {
        //Your custom logic here to determine if the local cal should be hidden.
        break;
    }

你可以在这里找到EKSourceType常量的完整列表: http://developer.apple.com/library/ios/#documentation/EventKit/Reference/EKSourceClassRef/Reference/Reference.html



文章来源: How to decide whether the default EKCalendar 'Calendar' can be hidden?