在我的项目中,我正在使用PDFJS
库。我正在加载本地 pdf 文件UIWebView
。但这会占用大量 RAM 内存,并且有时会崩溃。为了避免这种情况,我想使用WKWebView
.
在UIWebview
,我是这样使用的(self
指的是子类UIView
)
UIWebView *uiWebview = [[UIWebView alloc] initWithFrame:self.frame];
[self addSubview:uiWebview];
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"swift_tutorial" ofType:@"pdf"];
NSString *sPath = [[NSBundle mainBundle] pathForResource:@"viewer" ofType:@"html" inDirectory:@"PDFJS/web"];
NSString *finalPath = [NSString stringWithFormat:@"%@?file=%@#page=1",sPath,filePath];
self.urlRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:finalPath]];
[uiWebview loadRequest:self.urlRequest];
当我在上面的代码片段中打印 finalPath 时,控制台输出是/var/containers/Bundle/Application/DF419672-CF14-4B60-BE4F-EC0AC07C23AE/WebviewPOC.app/PDFJS/web/viewer.html?file=/var/containers/Bundle/Application/DF419672-CF14-4B60-BE4F-EC0AC07C23AE/WebviewPOC.app/swift_tutorial.pdf#page=1
在WKWebView
, loadFileURL
,loadHTMLString
方法可用于加载本地 html 文件或本地 pdf 文件,效果很好。但不是两者兼而有之。对于这个 html 文件,如何附加本地 pdf 路径并加载到WKWebView
?
任何帮助表示赞赏。