问题
I am trying to download and open .ics file in my app.
I found few question, and here's some code I am using
// NSString *path = [[NSBundle mainBundle] pathForResource:@"http://www.nmsd.wednet.edu//site/handlers/icalfeed.ashx?MIID=607" ofType:@"ics"];
NSURL *url = [NSURL fileURLWithPath:@"http://www.nmsd.wednet.edu//site/handlers/icalfeed.ashx?MIID=607"];
UIDocumentInteractionController *dc = [UIDocumentInteractionController interactionControllerWithURL:url];
dc.delegate = self;
[dc presentPreviewAnimated:YES];
Nothing at all happens. no errors at all. Would it be easier to look for a library to achieve this.
回答1:
If you have a link to remote .ics
file, then prepare it for Safari
.
Let's suppose that you have a link to iCal
file:
"pl-dev2.office.org/events/sync.ics?t=90613b6c7f8".
Just add prefix webcal://
to your link.
Swift
let link = "webcal://pl-dev2.office/events/sync.ics?t=90613b6c7f8"
let webcal = NSURL(string: link)
UIApplication.sharedApplication().openURL(webcal)
Objective-C
NSString *link = "webcal://pl-dev2.office/events/sync.ics?t=90613b6c7f8"
NSUrl *webcal = [NSURL URLWithString:link];
[[UIApplication sharedApplication] openURL:webcal];
Safari will sync it in your Calendar app for You.
来源:https://stackoverflow.com/questions/24315548/how-can-i-open-calendar-ics-files-in-ios