How can I set the UIDocumentInteractionController Calendar as an option to open a .ics file?

I intercept the URL in the web browser that I use in my application to download the file it refers to, rather than just opening it in webview. Link to the .ics file. Therefore, I upload this file to a temporary directory and then export it to an instance of UIDocumentInteractionController, but Calendar is not displayed as one of the applications that opens this .ics file, only Mail, DropBox and Copy.

As you can see in the numbered line in the code below, I tried to make the link open with webcal: // in front, not http: //, and also manually set the UIDocumentInteractionController UTI to no avail. Is there a reason my local .ics file would not show Calendar as an option to open it?

//Test for link to an ics file if ([urlToLoad rangeOfString:@"GetSingleEventCalendarFile" options:NSCaseInsensitiveSearch].location != NSNotFound) { //urlToLoad = [urlToLoad stringByReplacingOccurrencesOfString:@"http" withString:@"webcal"]; //NSData *contact = [NSData dataWithContentsOfURL:[NSURL URLWithString:webCalProtocol]]; //return NO; NSURLRequest *req = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:urlToLoad]]; [NSURLConnection sendAsynchronousRequest:req queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *resp, NSData *respData, NSError *error){ NSString *urlString = [req.URL absoluteString]; NSString *actIdAndRest = [urlString substringFromIndex:[urlString rangeOfString:@"="].location + 1]; NSString *actId = [actIdAndRest substringToIndex:[actIdAndRest rangeOfString:@"&"].location]; NSString *fileName = [[@"activity" stringByAppendingString:actId] stringByAppendingString:@".ics"]; NSString * path = [NSTemporaryDirectory() stringByAppendingPathComponent:fileName]; NSError *errorC = nil; BOOL success = [respData writeToFile:path options:NSDataWritingFileProtectionComplete error:&errorC]; if (success) { NSBundle * bundleContaining = [NSBundle bundleWithPath:NSTemporaryDirectory()]; NSLog(@"%@", bundleContaining); NSURL *fileURL = [bundleContaining URLForResource:fileName withExtension:@"ics"]; documentController = [UIDocumentInteractionController interactionControllerWithURL:fileURL]; //documentController.UTI = @"ics"; [documentController presentOptionsMenuFromRect:CGRectZero inView:self.view animated:YES]; } else { NSLog(@"fail: %@", errorC.description); } }]; } 
+2
source share

All Articles