-(void)openFileUsingExtension:(NSString*)extension {
NSString *path = [NSString stringWithFormat:@"%@temp.%@",NSTemporaryDirectory(),extension];
NSLog(@"%@",path);
if ([objectFromNSData writeToFile:path atomically:YES]) {
NSLog(@"written");
NSURL *url = [NSURL fileURLWithPath:path];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[self.webview loadRequest:request];
self.webview.scalesPageToFit = YES;
self.webview.delegate = self;
[self.view addSubview:self.webview];
}
}
then you can remove the file inside the UIWebViewDelegate method:
- (void)webViewDidFinishLoad:(UIWebView *)webView{
NSString *path = [NSString stringWithFormat:@"%@temp.%@",NSTemporaryDirectory(),extension];
[[NSFileManager defaultManager] removeItemAtPath:path error:nil];
}
一旦保存在iPhone上的文件,然后尝试使用UIDocumentinteractionController或QLPreviewController – nikhil84
[显示PPT,DOC,XLS和在UIWebView中不工作,但确实PDF(HTTP的可能重复它打开://计算器.com/questions/2520137/displays-ppt-doc-and-xls-in-uiwebview-doesnt-work-but-pdf-does) –
@ nikhil84 ...这里我没有在设备中保存文档。我在webview中直接加载。 –