使用WKWebView加载本地pdf
- (void)viewDidLoad {
[super viewDidLoad];
WKWebView *webView = [[WKWebView alloc] initWithFrame:self.view.bounds];
NSURL *pdfUrl = [NSURL URLWithString:[[NSBundle mainBundle] pathForResource:@"hello" ofType:@"pdf"]];
// NSURL *pdfUrl = [NSURL URLWithString:@"http://www.taobao.com"];
NSURLRequest *request = [NSURLRequest requestWithURL:pdfUrl];
[webView loadRequest:request];
[self.view addSubview:webView];
}
问题来了
加载网络链接的时候正常加载;
但是、
加载本地pdf的时候为空白页、
控制台log输出:
2020-05-22 15:19:12.172698+0800 appDemo[23683:1471101] WF: === Starting WebFilter logging for process 学谷智能
2020-05-22 15:19:12.172771+0800 appDemo[23683:1471101] WF: _userSettingsForUser mobile: {
filterBlacklist = (
);
filterWhitelist = (
);
restrictWeb = 1;
useContentFilter = 0;
useContentFilterOverrides = 0;
whitelistEnabled = 0;
}
2020-05-22 15:19:12.172812+0800 appDemo[23683:1471101] WF: _WebFilterIsActive returning: NO
然后很纠结、再然后就沙雕了
//既然是加载本地的,那就是用fileURLWithPath啊
NSURL *pdfUrl = [NSURL fileURLWithPath:path];
//谁让我用了
[NSURL URLWithString:];