Question

I am using the EKEventEditViewController to allow adding events from my application to the iPhone calendar. This is currently the code that I am using:

    [self.store requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) {
        if (!granted) { return; }
        EKEvent *storedEvent = [EKEvent eventWithEventStore:self.store];
        storedEvent.title = self.selectedEvent.title;
        storedEvent.startDate = self.selectedEvent.date;
        storedEvent.endDate = [NSDate dateWithTimeInterval:60*60 sinceDate:self.selectedEvent.date];
        storedEvent.notes = self.selectedEvent.comments;
        [storedEvent setCalendar:[self.store defaultCalendarForNewEvents]];
        self.eventController.event = storedEvent;
        self.eventController.eventStore = self.store;
        self.eventController.editViewDelegate = self;
        [self presentViewController:self.eventController animated:YES completion:nil];
    }];

This code is taking upwards of 10 seconds to produce the necessary view event though I have pre-inited both the view controller and the EventStore. Is there a way to make this faster, or do I just need to put up a spinner and tell the users to wait?

Was it helpful?

Solution

The completion handler will be called on an arbitrary queue. Inside the completion block dispatch UIKit-related stuff on the main thread:

[[NSOperationQueue mainQueue] addOperationWithBlock:^{
    self.eventController.event = storedEvent;
    self.eventController.eventStore = self.store;
    self.eventController.editViewDelegate = self;
    [self presentViewController:self.eventController animated:YES completion:nil];
}];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top