How to get calendar provider (Google, Apple, Yahoo etc.) from EKEventStore

447 views Asked by At

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];
        });
    }
1

There are 1 answers

0
rckoenes On BEST ANSWER

You can't really get the service provider, you can detect the kind of service used by looking a the sourceType in EKSource.