2

This code has been working fine prior to ios 11, but now in ios 11 the ID works fine but the title returns null.

NSArray *availablePersonalCalendars = [eventStore calendarsForEntityType:EKEntityTypeEvent];

for (EKCalendar *cal in availablePersonalCalendars) {

    NSLog(@"ID: %@", cal.calendarIdentifier);
    NSLog(@"Title: %@", cal.title)
}

Please help me out if you know how to fix this. Thanks,

Mona
  • 5,939
  • 3
  • 28
  • 33

2 Answers2

2

I have used this code and is working correctly in iOS 11:

EKEventStore *store = [[EKEventStore alloc] init];
[store requestAccessToEntityType:EKEntityTypeEvent
                      completion:^(BOOL granted, NSError * _Nullable error) {
       NSArray *availablePersonalCalendars = [store calendarsForEntityType:EKEntityTypeEvent];

       for (EKCalendar *cal in availablePersonalCalendars) {

          NSLog(@"ID: %@", cal.calendarIdentifier);
          NSLog(@"Title: %@", cal.title);
       }
  }];

Also be sure to include in the plist the NSCalendarsUsageDescription key, with a explanatory text of how is going to be used this information.

https://developer.apple.com/library/content/documentation/General/Reference/InfoPlistKeyReference/Articles/CocoaKeys.html#//apple_ref/doc/uid/TP40009251-SW15

Dailos Medina
  • 161
  • 1
  • 6
  • 4
    Good and complete answer. For my case it turned out my problem was solved by defining the EKEventStore *store as a class variable instead of a local variable. – Mona Sep 15 '17 at 17:10
1

You should store reference to your EKEventStore object. Somehow its related to missing calendars' titles. Dont forget to request permissions before querying calendars.

Objective-C:

@interface Some ()

@property (nonatomic) EKEventStore *store;
@property (nonatomic) NSArray<EKCalendar *> *calendars;

@end

@implementation Some

- (void)prepare
{
  self.store = [EKEventStore new];
  self.calendars = @[];
}

- (void)loadCalendars
{
  self.calendars = [self.store calendarsForEntityType:EKEntityTypeEvent];
}

@end

Swift:

let store = EKEventStore()
var calendars: [EKCalendar] = []

func loadCalendars() {
  calendars = store.calendars(for: .event)
}
Timur Bernikovich
  • 5,660
  • 4
  • 45
  • 58