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.
我想在UIWebView中显示pdf文件。我的PDF来自Web服务,我能够成功地将它存储在文档目录中。但是当我尝试将PDF url加载到我的UIWebView中时,它会显示一个空白的webview。没有报告错误。
Does anyone have an idea as to what might be going wrong here or how I can better debug this problem?
有没有人知道这里可能出现的问题或者我如何更好地调试这个问题?
1 个解决方案
#1
1
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:-
使用调试器检查url的内容。它应该指向确切的pdf位置。此外,您可以使用UIWebView的委托方法: -
-(void)webViewDidFinishLoad:(UIWebView *)webView;
-(void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error;
#1
1
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:-
使用调试器检查url的内容。它应该指向确切的pdf位置。此外,您可以使用UIWebView的委托方法: -
-(void)webViewDidFinishLoad:(UIWebView *)webView;
-(void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error;