How can I open calendar .ics files in ios?

旧时模样 提交于 2019-12-07 14:55:49

问题


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

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