使用 AsiHttpRequest 和 UIWebView 查看文档(pdf、doc、xls)的最佳方式是什么???我尝试了以下操作,但 UIWebView 正在显示 html:
NSString * baseURL = @"http://xxxxxx/open-api/v1/";
NSString * itemRef = @"item/133/attachment/test.pdf";
NSString *urlString = [NSString stringWithFormat:@"%@%@", baseURL, itemRef];
NSURL *url = [NSURL URLWithString:urlString];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setUsername:@"xx"];
[request setPassword:@"xx"];
[request startSynchronous];
NSError *error = [request error];
if (!error) {
[self.webView loadHTMLString:[request responseString] baseURL: [request url]];
}
else {
NSLog(@"Error: %@", error );
}
设置基本身份验证和标头值需要 AsiHttpRequest...谢谢!
好吧,公平地说,您告诉它显示 HTML,所以结果并不意外:-)
您需要在本地下载 pdf 文件:
NSString *tmpLocation = // some temporary file location
[request setDownloadDestinationPath:tmpLocation]];
[request startSyncronous];
然后在UIWebView中查看:
NSURL *url = [NSURL fileURLWithPath:tmpLocation];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[webView loadRequest:requestObj];
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)