繁体   English   中英

在UIWebView上打开本地pdf文件时导致应用程序崩溃

[英]Getting application crash during opening a local pdf file on UIWebView

- (void) viewWillAppear:(BOOL)animated
{

 [super viewWillAppear:animated];

    NSString *path = [[NSBundle mainBundle] pathForResource:@"About" ofType: @"pdf"];

    NSLog(@"%@", path);

    NSURL *targetURL = [NSURL fileURLWithPath:path];

    NSURLRequest *request = [NSURLRequest requestWithURL:targetURL];

    [_webView loadRequest:request];

}

只需在Web视图中使用以下代码即可打开PDF

NSString *filePath = [[NSBundle mainBundle] pathForResource:@"About" ofType:@"pdf"]; 
[self.webVctr loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:filePath]]];

并查看PDF是否存在?

这个想法可能会对你有所帮助

快乐编码..

尝试这个:

在里面

UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(10, 10, 200, 200)];

NSString *path = [[NSBundle mainBundle] pathForResource:@"About" ofType:@"pdf"];
NSURL *targetURL = [NSURL fileURLWithPath:path];
NSURLRequest *request = [NSURLRequest requestWithURL:targetURL];
[webView loadRequest:request];

[self.view addSubview:webView];
[webView release];

这是与Web视图上的pdf加载无关的其他一些问题。 我交叉检查并找到了崩溃的实际原因。 无论如何,谢谢你的帮助

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM