我想在 iPhone日历中添加活动,我在iPhone日历中成功添加了活动。但是,我希望获得所有当前月份活动,并且我想在 MFMailComposer 中附加事件文件(.ical)。
答案 0 :(得分:3)
阅读事件非常简单。
// 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];
apple docs中的更多信息。
要获得月末的开始和结束,您可以使用此项目中的示例:https://github.com/melsam/NSDateCategoryForReporting
并以此为例将如何将事件导出到.ical文件 https://github.com/mysterioustrousers/EKEventToiCal/blob/master/EKEventToiCal/
要发送.ical文件,请使用IronManGill的代码回答,但将mimeType更改为text / calendar
[picker addAttachmentData:data mimeType:@"text/calendar" fileName:@"/abc.ical"];
答案 1 :(得分:0)
我可以为您提供解决方法。如果您获得 .ical文件,则可以访问它。您可以将其转换为 .zip文件,请浏览以下链接: -
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
然后使用此
将其与MFMailComposer
中的电子邮件一起附加
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];
希望这会有所帮助。