无法在iOS8beta5中使用UIWebView打开PDF文件 [英] Cannot open PDF file using UIWebView in iOS8beta5

查看:200
本文介绍了无法在iOS8beta5中使用UIWebView打开PDF文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有工作项目,其中我在UIWebView中显示 pdf文件

iOS8beta5中使用XCode5测试我的应用程序,它不起作用

日志中显示无法找到PDF标题:'%PDF'未找到 < br>



我使用以下代码创建示例应用程序也有同样的问题

代码:

I have working project in which i display pdf file in UIWebView
While testing my application in iOS8beta5 with XCode5, it did not work
In log it display failed to find PDF header : '%PDF' not found


I create sample application with below code which also have same problem
CODE :

self.myWebView.delegate = self;
NSString *path = [[NSBundle mainBundle] pathForResource:@"201" ofType:@"pdf"];
NSURL *targetURL = [NSURL fileURLWithPath:path];
NSURLRequest *request = [NSURLRequest requestWithURL:targetURL];
[self.myWebView loadRequest:request];



我阅读发行说明,Apple写道那个
Quicklook框架可能在某个应用程序中没有显示PDF文件
但他们没有提到任何关于 UIWebView的事情


I read release note, Apple wrote that Quicklook framework may did not display PDF file in some application but they did not mention any thing about UIWebView,

参考



注意:

iOS8beta4中没有出现此问题。

在XCode6 + iOS8beta5中也会出现同样的问题。

我也检查了不同的PDF文件但是有同样的问题。


问题:

1]是否有人针对上述问题进行了修复?

如果是,请提供一些示例代码。


NOTE :
This problem was not came in iOS8beta4.
Same problem is also occur in XCode6 + iOS8beta5.
I also check with different PDF files but have same problem.
QUESTION :
1] Is there any one had done fix for the above problem ?
If yes, please provide me some sample code.

推荐答案

我找到了一种在WebView中查看PDF的解决方法

I found a workaround for viewing the PDF in WebView

// Create pdf path & url
NSString *path = [[NSBundle mainBundle] pathForResource:@"201" ofType:@"pdf"];
NSURL *targetURL = [NSURL fileURLWithPath:path];

// Load pdf in WebView
NSData *pdfData = [[NSData alloc] initWithContentsOfURL:targetURL];
[self.webView loadData:pdfData MIMEType:@"application/pdf" textEncodingName:@"utf-8" baseURL:nil];

这篇关于无法在iOS8beta5中使用UIWebView打开PDF文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆