Attach iCal File in MFMailComposerController?

点点圈 提交于 2019-12-08 11:52:09

问题


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.


回答1:


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



回答2:


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.



来源:https://stackoverflow.com/questions/18096065/attach-ical-file-in-mfmailcomposercontroller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!