在UIWebView中查看PDF

时间:2012-11-19 23:54:38

标签: ios pdf uiwebview

我的应用的“支持文件”文件夹包含名为test.pdf的文档。 尝试使用ViewDidLoad中的以下代码查看pdf文件,显示一个空的UIWebView:

NSString *testPath = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"pdf"];
NSURL *testURL = [NSURL URLWithString:testPath];
NSURLRequest *testRequest = [NSURLRequest requestWithURL:testURL];

UIWebView *documentWebView;

documentWebView = [[UIWebView alloc] initWithFrame:CGRectMake(10, 24, 300, 400)];

[documentWebView loadRequest:testRequest];

[self.view addSubview:documentWebView];

有谁能告诉我为什么PDF不会显示在网页视图中?感谢。

1 个答案:

答案 0 :(得分:1)

这一行:

NSURL *testURL = [NSURL URLWithString:testPath];

需要:

NSURL *testURL = [NSURL fileURLWithPath:testPath];
相关问题