"URL can't be shown" suddenly appearing in iOS 10 UIWebView for redirects.

We have a UIWebView that uses a custom NSURLProtocol handler. After upgrading to iOS 10.x, it appears that any redirect that calls:


[self.client URLProtocol:self wasRedirectedToRequest:new_request redirectResponse:response];


Response:

<NSHTTPURLResponse: 0x17462fc40> { URL: https://secure.leaseweb.com/ } { status code: 302, headers {
    "Content-Length" = 81;
    "Content-Type" = "text/html; charset=utf-8";
    Date = "Mon, 03 Oct 2016 19:44:29 GMT";
    Location = "/dashboard";
    Server = nginx;
    Vary = "Accept-Encoding";
    "X-Frame-Options" = Deny;
} }


Triggers a "URL Cannot Be Loaded" error from UIWebKit:

Error Domain=WebKitErrorDomain Code=101 "The URL can’t be shown" UserInfo={NSErrorFailingURLStringKey=https://secure.leaseweb.com/, NSLocalizedDescription=The URL can’t be shown, NSErrorFailingURLKey=https://secure.leaseweb.com/}


This is a change from iOS 9. Any advice is greatly appreciated.


-J


UPDATE w/ Workaround:


Found the trigger...if you build the NSURL for the redirect using the relativeToURL invocation:

[NSURL URLWithString:[[response allHeaderFields] objectForKey:@"Location"] relativeToURL:self.request.URL]


...UIWebView will treat it as if the hostname in the NSURL is empty and give you "The URL can't be shown" even though NSURL.host is not nil. This really seems like a bug in iOS 10.


The work around is to not use relativeToURL but use a fully-qualified URL string when initializing NSURL.