Xcode Version 12.5 (12E262)
Code Block objc // Test URL https://dwarf.sogoucdn.com/trans/durl/31-193475685vgiwgIi7?action=d&ow_name=testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttest.zip
I opened this URL in Safari and Chrome, and I found that Chrome displayed the correct name "testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttest.zip", while the file name downloaded by Safari displayed "31-193475685vgiwgIi7".
I captured the WKNavigationResponse object in the delegate of WKWebView and found that the "Content-Disposition" was incomplete.
I tried other URL addresses. If the filename in "Content-Disposition" is very long, this bug will appear.
Code Block objc - (void)webView:(WKWebView *)webView decidePolicyForNavigationResponse:(WKNavigationResponse *)navigationResponse decisionHandler:(void (^)(WKNavigationResponsePolicy))decisionHandler { if ([navigationResponse.response isKindOfClass:[NSHTTPURLResponse class]]) { NSHTTPURLResponse *response = (NSHTTPURLResponse*)navigationResponse.response; NSString *contentDisposition = [response.allHeaderFields valueForKey:@"Content-Disposition"]; NSLog(@"%@",contentDisposition); } } /* "Content-Disposition" = ( "attachment; filename=\"testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttest" ); */
If I use NSURLSessionDataTask to request, I can get the complete "Content-Disposition"
Code Block objc "Content-Disposition" = ( "attachment; filename=\"testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttest.zip\"; filename*=UTF-8''testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttest.zip" );
This question is very important because I embed WKWebView in my app and use it to support file downloading. WKWebView does not seem to support downloading files, but I need to complete its downloading ability.
This problem seems to exist on iOS too
I want to know how I can solve this problem