簡體   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