iOS 18 WKWebView images are not loading, no errors in older versions.
The example while loading HTML is as follows. A problem occurs when you pull an image from a url. To get a URL image you need a cookie or something. I add them too, but it doesn't work on iOS 18. I get the error "An error occurred trying to load the resource." and a blue question mark on the screen.
webView.configuration.websiteDataStore.httpCookieStore.setCookie(cookie)
<html>
<head>
<style>
body {
font-family: -apple-system;
margin: 0;
padding: 0;
text-align: center;
}
img {
width: 100%;
height: auto;
}
</style>
</head>
<body>
<h1>Resim Görüntüleme</h1>
<img src="https://xx.***.xx/example.png">
</body>
</html>
"""
Yes, I have identified the issue. Normally, when loading this image URL with URLRequest, there is no problem, and cookies are set when loaded in the WebView. However, my problem occurs here:
webView.loadHTMLString(htmlString, baseURL: baseURL)
If you leave the baseURL part as nil, the cookies are not recognized, and the images could not be loaded in iOS 18. If you set your default domain URL in the baseURL part, the issue is resolved because the WebView sets the cookies to the baseURL and loads the HTML from there. Thank you.