How to decide whether the default EKCalendar 'Calendar' can be hidden?

夙愿已清 提交于 2019-12-06 22:46:46

问题


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.


回答1:


To answer your question in bold, there isn't a magic property you can use to determine if a calendar should be hidden or displayed.

However, if your theory is correct about the Calendar app hiding the "local" calendar if other calendar types are available (iCloud/MobileMe, Exchange, CalDAV, etc), then you can mirror its logic in your code using the EKSource array in 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;
    }

You can find the full list of EKSourceType constants here: http://developer.apple.com/library/ios/#documentation/EventKit/Reference/EKSourceClassRef/Reference/Reference.html



来源:https://stackoverflow.com/questions/10530330/how-to-decide-whether-the-default-ekcalendar-calendar-can-be-hidden

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!