iOS 18 beta have issue when we load html string having secure media remote images those are unable to load on web view. shing question mark in place of images.
WKWebview not lading HTTPS images on iOS 18 beta
self.subTitleWebview.loadHTMLString(CommonUtility.getModifiedMediaBaseUrlInHTML(htmlToShow: htmlToShow), baseURL: Bundle.main.bundleURL)
above is my code to load html string but unable to load https remote images
Hi,
You can try WKURLSchemeHandler to load your images.
For example: Say we have a defined custom handler such as:
func webView(_ webView: WKWebView, start urlSchemeTask: WKURLSchemeTask) {
guard let url = urlSchemeTask.request.url else {
return
}
let type = url.lastPathComponent
...
You can check the type and decide on how to load the asset (locally, remotely, handling certain types of images, etc).
if let resource = Bundle.main.url(forResource: "image", withExtension: "png"),
let resourceData = try? Data(contentsOf: resource) {
data = resourceData
response = URLResponse(
url: url,
mimeType: "image/png",
expectedContentLength: data!.count,
textEncodingName: nil)
}
} else if type == LocalObjectType.https.rawValue {
if let resource = URL(string: "https://pngimg.com/uploads/frisbee/frisbee_PNG21.png"),
let resourceData = try? Data(contentsOf: resource) {
data = resourceData
response = URLResponse(
url: url,
mimeType: "image/png",
expectedContentLength: data!.count,
textEncodingName: nil)
}
} else if type == LocalObjectType.pdf.rawValue {
if let resource = Bundle.main.url(forResource: "image", withExtension: "pdf"),
let resourceData = try? Data(contentsOf: resource) {
data = resourceData
response = URLResponse(
url: url,
mimeType: "application/pdf",
expectedContentLength: data!.count,
textEncodingName: nil)
}
}
if let response = response, let data = data {
urlSchemeTask.didReceive(response)
urlSchemeTask.didReceive(data)
urlSchemeTask.didFinish()
}
The remote images should load if you handle the resource type appropriately.
Rico
WWDR - DTS - Software Engineer