xcode 无法在 iOS8beta5 中使用 UIWebView 打开 PDF 文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25256905/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 05:22:22  来源:igfitidea点击:

Cannot open PDF file using UIWebView in iOS8beta5

xcodeuiwebviewxcode5ios8xcode6

提问by Jageen

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

我有一个工作项目,我在 UIWebView 中显示pdf 文件在使用 XCode5
iOS8beta5 中测试我的应用程序时,它没有工作
日志中显示failed to find PDF header : '%PDF' not found



我用下面的代码创建了示例应用程序,它们也有同样的问题


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];



I read release note我阅读了发行说明,Apple 写道, Quicklook framework may did not display PDF file in some applicationQuicklook framework may did not display PDF file in some application但他们没有提到任何关于UIWebViewUIWebView在此处输入图片说明

Reference

参考



NOTE :注意:


这个问题不是在 iOS8beta4 中出现的。


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


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

QUESTION :问题:


1] 有没有人解决了上述问题?


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


回答by Jageen

I found a workaround for viewing the PDF in WebView

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

// 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];