title: Add an event into iCal in iPhone application
body: <p>There is a requirement in my application in which, when I take an appointment of a doctor for a particular day, that day should be added in iCal. and it should generate an alert view on that particular day.</p>
  
  <p>So, I am not getting how to add an event in iCal. Please give me some answer for this.</p>
  
  <p>The scenario is, I do have a string (NSString) of "date" and "notes" for that particular appointment. Then, how to insert all this information into iCal.</p>
  
  <p>Code:</p>
  
  <pre><code>- (NSArray *)fetchEventsForToday {
  
      NSDate *startDate = [NSDate date];
  
      // endDate is 1 day = 60*60*24 seconds = 86400 seconds from startDate
      NSDate *endDate = [NSDate dateWithTimeIntervalSinceNow:86400];
  
      // Create the predicate. Pass it the default calendar.
      NSArray *calendarArray = [NSArray arrayWithObject:defaultCalendar];
      NSPredicate *predicate = [self.eventStore predicateForEventsWithStartDate:startDate endDate:endDate 
                                                                      calendars:calendarArray]; 
  
      // Fetch all events that match the predicate.
      NSArray *events = [self.eventStore eventsMatchingPredicate:predicate];
  
      return events;
  }
  
  
  // Overriding EKEventEditViewDelegate method to update event store according to user actions.
  - (void)eventEditViewController:(EKEventEditViewController *)controller 
            didCompleteWithAction:(EKEventEditViewAction)action {
  
      NSError *error = nil;
      EKEvent *thisEvent = controller.event;
  
      switch (action) {
          case EKEventEditViewActionCanceled:
              // Edit action canceled, do nothing. 
              break;
  
          case EKEventEditViewActionSaved:
              // When user hit "Done" button, save the newly created event to the event store, 
              // and reload table view.
              // If the new event is being added to the default calendar, then update its 
              // eventsList.
              if (self.defaultCalendar ==  thisEvent.calendar) {
                  [self.eventsList addObject:thisEvent];
              }
              [controller.eventStore saveEvent:controller.event span:EKSpanThisEvent error:&amp;error];
              [self.tableView reloadData];
              break;
  
          case EKEventEditViewActionDeleted:
              // When deleting an event, remove the event from the event store, 
              // and reload table view.
              // If deleting an event from the currenly default calendar, then update its 
              // eventsList.
              if (self.defaultCalendar ==  thisEvent.calendar) {
                  [self.eventsList removeObject:thisEvent];
              }
              [controller.eventStore removeEvent:thisEvent span:EKSpanThisEvent error:&amp;error];
              [self.tableView reloadData];
              break;
  
          default:
              break;
      }
      // Dismiss the modal view controller
      [controller dismissModalViewControllerAnimated:YES];
  
  }
  
  // Set the calendar edited by EKEventEditViewController to our chosen calendar - the default calendar.
  - (EKCalendar *)eventEditViewControllerDefaultCalendarForNewEvents:(EKEventEditViewController *)controller 
  {
      EKCalendar *calendarForEdit = self.defaultCalendar;
      return calendarForEdit;
  }
  </code></pre>
  
  <p>I have used these functions and delegate methods. Please give me idea that, when the user gets alerted for the reminder, how to open up that information regarding that event?</p>