1
votes

Am getting the PDF file link from my web view. when i click that link, i want to open that PDF file in my iBook application.

i got the contents from server. I showed that content in UIWebview like this.

enter image description here

In this content have a PDF link "Emerging Trends in Real Estate". When i choose this link, i want to open this pdf file in iPhone PDF reader applications like iBook, Adobe Reader. When i click this link it goes to webView Delegate method

-(BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType
{
    NSURL* url = [request URL];
    NSLog(@"PDF URL : %@",url);
       if (UIWebViewNavigationTypeLinkClicked == navigationType)
    {
        if ([url isEqual:@"about:blank"])
        {
            return YES;
        }
        else
        {

            // Initialize Document Interaction Controller
            documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:url];
            // Configure Document Interaction Controller
            documentInteractionController.delegate = self;
            // Present Open In Menu
            [documentInteractionController presentOptionsMenuFromRect:CGRectZero inView:self.view animated:YES];

        }
    }
    return YES;
}

when compiler comes to else part i got an error. i displayed that error :

PDF URL : http://www.uli.org/wp-content/uploads/ULI-Documents/Emerging-Trends-in-Real-Estate-Americas-2014.pdf
2014-01-17 16:44:49.233 ULINewYork[3163:a0b] *** Assertion failure in -[UIDocumentInteractionController setURL:], /SourceCache/UIKit_Sim/UIKit-2903.23/UIDocumentInteractionController.m:1010
2014-01-17 16:44:49.234 ULINewYork[3163:a0b] *** WebKit discarded an uncaught exception in the webView:decidePolicyForNewWindowAction:request:newFrameName:decisionListener: delegate: <NSInternalInconsistencyException> UIDocumentInteractionController: invalid scheme http.  Only the file scheme is supported.

please give me some idea to handle this process.

1
Possible duplicate questionjohnMa
@Sabs Did you get this working?vignesh kumar
<p>Now in its 35th year,&nbsp;<a href=\"uli.org/wp-content/uploads/ULI-Documents/…\" onclick=\"javascript:_gaq.push(['_trackEvent','download','uli.org/wp-content/uploads/ULI-Documents/…);\" target=\"_blank\"><em>Emerging Trends</em>Sabs
&nbsp;<i>in</i><i>&nbsp;</i></a><i><a href=\"uli.org/wp-content/uploads/ULI-Documents/…\" onclick=\"javascript:_gaq.push(['_trackEvent','download','uli.org/wp-content/uploads/ULI-Documents/…);\" target=\"_blank\">Real Estate®</a>&nbsp;</i>is one of the most highly regarded annual industry outlooks for the real estate and land use industry.</p>"Sabs
@Sabs I found the same issue in the question below stackoverflow.com/questions/7377565/… may be it will help youvignesh kumar

1 Answers

1
votes

I tried the same way you have used along with the help of apple documentation. I get the same error you mentioned, then I download the DocInteraction application for understanding the UIDocumentInteractionController In that application they use this class to open the files located in local app sandbox or the files located in the main bundle.

If your Intention is to make the user read the pdf file then leave the handling of request to the webview itself(take out the -webView: shouldStartLoadWithRequest: delegate method) or else if you want to show some other options the ios device could do(print,preview,mail etc) with the file then you have to download that pdf file to local then set the url property of UIDocumentInteractionController object to the local path url you have saved the file before presenting.