Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't create event in default iOS 7 calendar

#import <EventKit/EventKit.h>

I can't create event in default iOS calendar.

EKEventStore *eventStore = [[EKEventStore alloc] init];
for (EKSource *source in eventStore.sources)
{
    if (source.sourceType == EKSourceTypeCalDAV || source.sourceType == EKSourceTypeLocal)
    {
        NSLog(@"I found it");
        break;
    }
}

Beginning from here it couldn't return any sources. When I build and run app there are no any requests to give its access to default calendar.

All in all I get an empty array:

[eventStore.sources count]

Even when I trying to add event without creating new calendar (using

[eventStore defaultCalendarForNewEvents]
like image 430
Rasim Avatar asked Mar 22 '23 04:03

Rasim


2 Answers

I guess there is problem in accessing EKEventStore, to check permission try following,

 EKEventStore *eventStore = [[EKEventStore alloc] init];
if ([eventStore respondsToSelector:@selector(requestAccessToEntityType:completion:)]){    
   [eventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error)
         {
             NSLog(@"GRANTED: %c", granted);
             for (EKSource *source in eventStore.sources)
             {
                 if (source.sourceType == EKSourceTypeCalDAV || source.sourceType == EKSourceTypeLocal)
                 {
                     NSLog(@"I found it");
                     break;
                 }
             }
         }];

}

Hope it Helps you..

like image 144
Toseef Khilji Avatar answered Apr 02 '23 11:04

Toseef Khilji


I have found problem:

[eventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) {
    // TODO
}];

I must request permission manually, thought permission set without it, I think it had fixed in iOS 7.0.2 build.

like image 44
Rasim Avatar answered Apr 02 '23 10:04

Rasim