gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 10:50:42 25 4
gpt4 key购买 nike

我有 工作项目其中我显示 UIWebView 中的 pdf 文件
中测试我的应用程序时带有 XCode5 的 iOS8beta5 , 这没用
日志它显示 failed to find PDF header : '%PDF' not found
我用下面的代码创建了示例应用程序,它们也有同样的问题
代码:

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

我阅读了发行说明 ,苹果写道 Quicklook framework may did not display PDF file in some application但他们没有提到关于 UIWebView的任何事情,
enter image description here

Reference

注意:
这个问题不是在 iOS8beta4 中出现的。
在 XCode6 + iOS8beta5 中也会出现同样的问题。
我也检查了不同的 PDF 文件,但有同样的问题。

问题:
1] 有没有人解决过上述问题?
如果是,请提供一些示例代码。

最佳答案

我找到了在 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];

关于xcode - 无法在 iOS8beta5 中使用 UIWebView 打开 PDF 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25256905/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com