Swift WKWebview load image from local bundle

97 Views Asked by At

I have created a Bundle Images.bundle which contains some images and I'm creating programmatically an HTML which displays the image pointing to the URL of the bundle image:

 //Here I simply add the basic HTML body tags... skipping this part
  if let imageURL: URL = ImageUtils.getMapUrlFromBundle(mapId) {

     htmlString += """
        <image
            width=\"\(imageURL.size.width)\"
            height=\"\(imageURL.size.height)\"
            href="\(imageURL)\">
        </image>
    """

Then loading this htmlString in the WKWebView:

webView.loadHTMLString(htmlString, baseURL: nil)

The problem is that the imageURL is not being recognized by the WKWebview:

href="file:///Users/Library/Developer/CoreSimulator/Devices/A12DFC-6401-3A42-LAS9-FLK129FDH/data/Containers/Bundle/Application/O12K3213-4ASD-123/Test.app/Images.bundle/test.webp"

I've read that using some custom scheme is the way to go but I'm new to iOS and I don't know exactly how to do this, any hint?

EDIT: Base64 conversion of the image is not a valid option.

0

There are 0 best solutions below