Displaying a PDF file into UIWebView
I want to display a pdf file in a UIWebView. My PDF is coming from a web service and I am able to store it in a documents directory successfully. But when I try to load the PDF url into my UIWebView, it displays a blank webview. No errors are reported.
Does anyone have an idea as to what might be going wrong here开发者_如何学C or how I can better debug this problem?
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
//Considering your pdf is stored in documents directory with name as "pdfFileName"
NSString *pdfPath = [[paths objectAtIndex:0]stringByAppendingPathComponent:@"mynewDocument.pdf"];
NSURL *url = [NSURL fileURLWithPath:pdfPath];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[webView loadRequest:requestObj];
Use debugger to check the contents of url. It should point to the exact pdf location.
Also, You can use UIWebView's delegate methods:-
-(void)webViewDidFinishLoad:(UIWebView *)webView;
-(void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error;
加载中,请稍侯......
精彩评论