0
votes

I'm attempting to set up an EKEventStore to (with their permission) display the user's calendar events in an iOS app.

The first couple of Apple documentation pages that I've come across on how to initialize the EKEventStore instance (1. Accessing the Event Store; 2. Reading and Writing Calendar Events) say to do so like this:

EKEventStore *eventStore = [[EKEventStore alloc] initWithAccessToEntityTypes:EKEntityMaskEvent];

However, in a fresh iOS application created using the latest Xcode (version 11.3) with the "Single Page Application" template, with the above line of code added to the viewDidLoad method of the ViewController.m, Xcode gives this error:

'initWithAccessToEntityTypes' is unavailable: not available on iOS

What's the correct way to initialize EKEventStore in an iOS app?

1

1 Answers

1
votes

Article EKEventStore implies that on iOS, you can just use the default init method on iOS:

In macOS, use initWithAccessToEntityTypes: instead of the default init method. Acceptable entity types are EKEntityMaskEvent for events and EKEntityMaskReminder for reminders.

I tried doing so in my app's ViewController.m:

#import <EventKit/EventKit.h>

// ...

- (void)viewDidLoad 
{
    EKEventStore *eventStore = [[EKEventStore alloc] init];

    // ...
}

This did work fine for me in my iOS app; I was able to proceed to use the eventStore to successfully retrieve calendar events (after the user granted permission at runtime).