I need to open a .ics file in my app.
I tried to open it like this:
NSURL *path = [[NSBundle mainBundle] URLForResource:@"myIcsName" withExtension:@"ics"];
[[UIApplication sharedApplication] openURL:path];
But nothing is happening.
How do I open the .ics file?
I just used the following code:
- (IBAction)displayICS:(id)sender
{
NSString *path = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"ics"];
NSURL *url = [NSURL fileURLWithPath:path];
UIDocumentInteractionController *dc = [UIDocumentInteractionController interactionControllerWithURL:url];
dc.delegate = self;
[dc presentPreviewAnimated:YES];
}
-(UIViewController *)documentInteractionControllerViewControllerForPreview:(UIDocumentInteractionController *)controller
{
return self;
}
I have found there are two projects that enable you to open an ICS file and get events, dates and other information out of it as Objective-C objects.
MXLCalendarManager seems to be a bit further along and will allow you to pull out the events from the ICS file search on date and add the events to the users iOS calendar. This might be what your looking for. GitHub Project MXLCalendarManager It also supports writing new ICS files.
I've created a project that uses the libical library written in C to parse the complete ICS file. The project is still in the early stages and could use some more tender care before its ready to just drop into a project. You can check it out at Github Project XbICalendar More details on libical can be found at GitHub Project libical
来源:https://stackoverflow.com/questions/22082043/open-ics-file-in-ios-app