Question

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.

Was it helpful?

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"];

OTHER TIPS

Well I can offer you a workaround. If you get the .ical file , have access to it. You could convert it into a .zip file , please go through these links :-

How can I create a zip file by using Objective C?

How to zip folders in iPhone SDK?

Creating zip files in ObjectiveC for iPhone

And then attach it alongwith the email in the MFMailComposer using this

MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init]; picker.mailComposeDelegate = self; NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

NSString *documentsDirectory = [paths objectAtIndex:0];    
NSString *WritableDBPath= [documentsDirectory stringByAppendingPathComponent:kFilename];    
NSData *data = [NSData dataWithContentsOfFile:WritableDBPath];    
[picker addAttachmentData:data mimeType:@"application/zip" fileName:@"/abc.zip"];
[picker setSubject:@"Database"];    
[picker setMessageBody:@"Database testing" isHTML:NO];    
[self presentModalViewController:picker animated:YES];

Hope this helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top