问题
Take a look at the documentation for EKCalendar. It's pretty simple, it has five properties, only one of which is a string called title
. Now if you have multiple calendars on your iPhone and you open iCal's Calendar settings, you can see that all calendars are nicely grouped by another string called account
.
What I can't figure out, is how to do the same, because although you can see the account
when you NSLog
a EKCalendar
instance, you can't access it:
EKCalendar <0x1851b0> {title = Work; type = CalDAV; account = some@addr.ess; allowsModify = YES; color = 0.690196 0.152941 0.682353 1.000000}
There is no account
property, and trying to access the valueForKey:@"account"
isn't working either, unsurprisingly.
So how do I get to that account
property? Such a simple thing, driving me nuts! Help is much appreciated.
Update: since iOS 5.0, EKCalendar has a source property.
回答1:
If you use class-dump on the iOS 4.3 (Simulator) SDK, you'll see that there's a read-only method -(id)accountName
. However, since it's not in the headers, it's unfortunately private API and you can't use it if you want your App to be accepted in the App Store.
I recommend that you file an enhancement request with Apple requesting that this method be made public.
Though thinking about it: If you're really desperate, why not parse the output of -[EKCalendar description]
? It's very very very bad style and it'll probably break in the future, but you might make it through the App Store review ;) In particular if you only use it for grouping and write your code extremely defensive so it doesn't break but simply doesn't group, should the output of the description
method be formatted differently.
回答2:
This information is not available in the 4.0 SDK. Have you looked at the developer previews of the forthcoming SDK to see if that might contain more information?
回答3:
And on iOS6? It seems the private property [EKCalendar accountName]
vanished. And [EKCalendar description]
does not contain account anymore. :
EKCalendar <0x200f50e0> {title = test@gmail.com; type = Exchange; allowsModify = YES; color = #44A703;}
The [EKCalendar source]
provides a EKSource
object, that has a title but this is not the name I typed when I created the account but seems to be a more generic name, e.g. Exchange, Other, CalDAV.
来源:https://stackoverflow.com/questions/6417632/how-to-access-an-ekcalendars-account-property