I'm pulling the calendars that synced on a device with the EventKit framework and getting the calendar title [email protected]
in a EKCalendar
object which is great! But we must know who is the service provider for this account. wW have if the suffix is "@gmail.com" so we know it is a Google account, but it could also be a google account with "@mycoolsite.com" So what do we do here? How can we actually get the service provider from the system?
Here is how we get the account title:
EKEventStore * eventStore = [[EKEventStore alloc] init];
NSMutableArray*calendars = [[NSMutableArray alloc]init];
[eventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) {
if (granted)
{
dispatch_async(dispatch_get_main_queue(), ^{
NSArray * accountsArray = [eventStore calendarsForEntityType:EKEntityTypeEvent];// ios 6 ^
for (int i = 0; i < [accountsArray count]; i++) {
NSString *cal = [[accountsArray objectAtIndex:i] valueForKey:@"title"];
if ([cal rangeOfString:@"@"].location != NSNotFound) {
[calendars addObject:[[accountsArray objectAtIndex:i] valueForKey:@"title"]];
}
}
[self gotCalendars:calendars];
});
}
You can't really get the service provider, you can detect the kind of service used by looking a the
sourceType
inEKSource
.