У меня есть UIWebView
. При щелчке по ссылке PDF
внутри этого UIWebView
Я хочу открыть его, используя UIDocumentInteractionController
.Недопустимая схема iOS UIDocumentInteractionController (null). Поддерживается только файловая схема
Вот мой код:
- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType {
NSString *path = [[request URL] path];
NSLog(@"current path %@", path);
NSLog(@"current request url %@", [request URL]);
if (navigationType == UIWebViewNavigationTypeLinkClicked) {
if([[path pathExtension] isEqualToString:@"pdf"]) {
NSLog(@"is PDF");
NSString *documentDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];
NSString *filePath = [NSString stringWithFormat:@"%@/%@", documentDir,@"filename.pdf"];
NSURLRequest *req = [NSURLRequest requestWithURL:[request URL]];
[NSURLConnection sendAsynchronousRequest:req queue:[NSOperationQueue currentQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
if (error) {
NSLog(@"Download Error:%@",error.description);
}
if (data) {
BOOL success = [data writeToFile:filePath atomically:YES];
NSLog(@"File is saved to %@",filePath);
if(success) {
NSURL *localUrl = [NSURL URLWithString:filePath];
if(localUrl) {
self.documentController = [UIDocumentInteractionController interactionControllerWithURL:localUrl];
self.documentController.delegate = self;
self.documentController.name = @"";
[self.documentController presentPreviewAnimated:YES];
}
}
}
}];
return NO;
}
}
return YES;
}
Я получаю сообщение об ошибке, показанное в названии Вопрос, когда линия выполнена: self.documentController = [UIDocumentInteractionController interactionControllerWithURL:localUrl];
Есть идеи? Это должно быть что-то очень глупое, но я не вижу его Спасибо!