我在viewDidLoad
NSURL *url = [NSURL URLWithString:URL_TO_DOWNLOAD];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setDelegate:self];
[request startAsynchronous];
[request setCacheStoragePolicy:ASICachePermanentlyCacheStoragePolicy];
完成此操作后,我想查看在UIWebView
内下载的网址(PDF)。我以编程方式创建UIWebView
但是我无法找到loadRequest
实际ASIHTTP请求的方法。
答案 0 :(得分:0)
您可以通过双向方式在设备中显示pdf。
首先直接将url传递给UIWebView,在这种情况下你不需要下载pdf文件
UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 360, 420)];
NSURL *targetURL = [NSURL URLWithString:@"http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIWebView_Class/UIWebView_Class.pdf"];
NSURLRequest *request = [NSURLRequest requestWithURL:targetURL];
[webView loadRequest:request];
[self.view addSubview:webView];
[webView release];
第二种方式,您首先需要下载(正如您所做),然后从您的应用程序包中获取pdf文件的路径,
UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(10, 10, 200, 200)];
NSString *pdfpath = [[NSBundle mainBundle] pathForResource:@"mypdf" ofType:@"pdf"];
NSURL *pdfURL = [NSURL fileURLWithPath:pdfpath ];
NSURLRequest *pdfRequest = [NSURLRequest requestWithURL:pdfURL ];
[webView loadRequest:pdfRequest];
[self.view addSubview:webView];
[webView release];