2

In my app, the user can create events. This is achieved by presenting the user the UI of iOS for creating an event:

    - (IBAction)addTermin:(id)sender
    {
        // Create an instance of EKEventEditViewController
    EKEventEditViewController *addController = [[EKEventEditViewController alloc] init];

    // Set addController's event store to the current event store
    addController.eventStore = self.eventStore;
        addController.editViewDelegate = self;
        [self presentViewController:addController animated:YES completion:nil];
    }

So, I implement the delegate method:

    - (void)eventEditViewController:(EKEventEditViewController *)controller
      didCompleteWithAction:(EKEventEditViewAction)action
   { 
        MRHomeViewController * __weak weakSelf = self;
    // Dismiss the modal view controller
    [self dismissViewControllerAnimated:YES completion:^
     {
         if (action != EKEventEditViewActionCanceled)
         {
             dispatch_async(dispatch_get_main_queue(), ^{
                 // Re-fetch all events happening in the next 24 hours
                 weakSelf.eventsList = [self fetchEvents];
                 // Update the UI with the above events
                 [weakSelf.termineTableView reloadData];
             });
         }
     }];
}

So, later I want to retrieve the events a user has created. I was thinking , that somewhere, somehow in the delegate method, I can obtain a reference to the new created event?

Or is there another way to later fetch only events created by the user?

mrd
  • 4,561
  • 10
  • 54
  • 92

1 Answers1

1

To make this work, you need to first create a new EKEvent, keep a reference to it, and pass it into your EKEventEditViewController:

    self.newEvent = [EKEvent eventWithEventStore:self.eventStore];
    addController.event = newEvent;

In the delegate method, check for EKEventEditViewActionSaved and then consult self.newEvent to find what you need about the event. If you want to maintain a longer term reference to the event, you can store the eventIdentifier or other fields for later lookup.

mygzi
  • 1,303
  • 1
  • 11
  • 21