[URL Loading System] - (NSCachedURLResponse *)cachedResponseForRequest:(NSURLRequest *)request returns nil for UIWebView in iOS 12

Originator:donnie.smith
Number:rdar://46828356 Date Originated:19-Dec-2018 11:05 AM
Status:Open Resolved:
Product:iOS + SDK Product Version:iOS 12.0 (16A366)
Classification:Other Bug Reproducible:Always
 
Summary:
- (NSCachedURLResponse *)cachedResponseForRequest:(NSURLRequest *)request returns nil for UIWebView in iOS 12. 
In iOS 11 it returns a valid cached response.

Steps to Reproduce:
In UIWebView delegate method webViewDidFinishLoad: add the following code:

NSCachedURLResponse *cachedResponse = [[NSURLCache sharedURLCache] cachedResponseForRequest:webView.request];

Expected Results:
cachedResponse contains a non-nil http response object with a status code.

Actual Results:
cachedResponse is nil.

Version:
iOS 12.0 (16A366)

Notes:
Our real use case is that we have an SDK that tracks the network requests/responses in apps.

To track UIWebView we swizzle webViewDidFinishLoad: and call cachedResponseForRequest: to track the response status code. This approach worked until iOS 12.

We use a different mechanism (swizzle webView:decidePolicyForNavigationResponse:decisionHandler:) to track response in WKWebView and that still works correctly in iOS 12.

I thought this could be related to https://bugs.webkit.org/show_bug.cgi?id=185990 but the WebKit developer says it isn’t and they asked me to file a radar.

Thanks

Comments

Apple updated radar with comment "DUPLICATE OF 43866293"

By donnie.smith at Dec. 26, 2018, 3:18 a.m. (reply...)

Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!