objective-cnulltitleios11ekcalendar

EKCalendar title returns null ios 11


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,


Solution

  • 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