Search code examples
iphoneicalendareventkit

Attach iCal File in MFMailComposerController?


I want to add Event in my iPhone Calendar, i Successfully add the Event in my iPhone calendar. But, i want to get the all Current Month event and i want to attach that Event file (.ical) in my MFMailComposer.


Solution

  • Reading events is very simple.

    // Create the predicate from the event store's instance method
    NSPredicate *predicate = [store predicateForEventsWithStartDate:startOfTheMonth
                                                            endDate:endOfTheMonth
                                                          calendars:nil];
    // Fetch all events that match the predicate
    NSArray *events = [store eventsMatchingPredicate:predicate];
    

    More information in apple docs.

    To get start and end of the month you can use example from this project: https://github.com/melsam/NSDateCategoryForReporting

    And use this as an example how to export Events to .ical file https://github.com/mysterioustrousers/EKEventToiCal/blob/master/EKEventToiCal/

    To send .ical file use the code from IronManGill answer but change mimeType to text/calendar

    [picker addAttachmentData:data mimeType:@"text/calendar" fileName:@"/abc.ical"];