WKWebView 载入pdf时显示不对问题

后台返回数据如下

HTTP/1.1 200 OK

Server: Apache-Coyote/1.1

X-Content-Type-Options: nosniff

X-XSS-Protection: 1; mode=block

Cache-Control: no-cache, no-store, max-age=0, must-revalidate

Pragma: no-cache

Expires: 0

Content-Disposition: attachment; filename="444ccd88d31c4eb8873606b12a360013.pdf"

Content-Type: application/octet-stream;charset=UTF-8

Transfer-Encoding: chunked

Date: Tue, 17 Jul 2018 06:24:27 GMT

//

- (WKWebView*)mWebView {

    if(_mWebView==nil) {

        _mWebView = [[WKWebView alloc] init];

        _mWebView.UIDelegate=self;

        _mWebView.navigationDelegate = self;

        [_mWebView setTranslatesAutoresizingMaskIntoConstraints:NO];

        [self.view addSubview:_mWebView];


        NSLayoutConstraint *constraint1 = [NSLayoutConstraint constraintWithItem:_mWebView attribute:NSLayoutAttributeTrailing relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeTrailing multiplier:1 constant:0];

        NSLayoutConstraint *constraint2 = [NSLayoutConstraint constraintWithItem:_mWebView attribute:NSLayoutAttributeLeading relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeLeading multiplier:1 constant:0];

        NSLayoutConstraint *constraint3 = [NSLayoutConstraint constraintWithItem:_mWebView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeBottom multiplier:1 constant:0];

        NSLayoutConstraint *constraint4 = [NSLayoutConstraint constraintWithItem:_mWebView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeTop multiplier:1 constant:0];

        [self.viewaddConstraint:constraint1];

        [self.viewaddConstraint:constraint2];

        [self.viewaddConstraint:constraint3];

        [self.viewaddConstraint:constraint4];

        [self.view layoutIfNeeded];

    }


    return _mWebView;

}

- (void)viewDidLoad {

    [super viewDidLoad];

    // Do any additional setup after loading the view from its nib.


    NSURL *url = [NSURL URLWithString:self.url];

    [self.mWebView loadRequest:[NSURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:30]];

}

//如果不添加如下实现,pdf展示时,是以类似于txt方式呈现

- (void)webView:(WKWebView*)webView decidePolicyForNavigationResponse:(WKNavigationResponse*)navigationResponse decisionHandler:(void(^)(WKNavigationResponsePolicy))decisionHandler {

    decisionHandler(WKNavigationResponsePolicyAllow);

    NSLog(@"%s", __FUNCTION__);

}

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容