UIWebView doesn't load images from protocol-relative URL

我的未来我决定 提交于 2019-12-05 07:15:57

I inspected the page opened in WebView and saw weird requests there. They looked like regular URLs, but with applewebdata scheme, e.g. applewebdata://art-u1.infcdn.net/articles_uploads/2/2586/thumb/3Dtouch%20Main-665x.png. Yay! It doesn't know the "base" scheme for the relative URL //art-u1.infcdn.net/articles_uploads/2/2586/thumb/3Dtouch%20Main-665x.png and gives it that Apple's fake scheme. So... the problem is here:

- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
    [m_webView loadData:webdata
               MIMEType:@"text/html"
       textEncodingName:@"UTF-8"
                baseURL:nil]; /// WTF!
}

Solution: just save the initial URL to some m_currentPageUrl when starting the request, and then pass it to where it's meant to be. :)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!