I am using amazon affiliate image links in my website that is then converted to an App using the WKWebView in Swift 4.
The Amazon affiliate link works perfectly fine if I access the webpage directly from Safari or any other browser. But the image is not showing in the app that is using WKWebView: a small question mark icon is displayed instead, and when I click the small icon it opens the right amazon link.
Here is my ViewController.swift:
import UIKit
import WebKit
class ViewController: UIViewController, WKNavigationDelegate {
var webView: WKWebView!
override func loadView() {
webView = WKWebView()
webView.navigationDelegate = self
view = webView
}
override func viewDidLoad() {
super.viewDidLoad()
// 1
let url = URL(string: "http://myurl/")!
webView.load(URLRequest(url: url))
// 2
let refresh = UIBarButtonItem(barButtonSystemItem: .refresh, target: webView, action: #selector(webView.reload))
toolbarItems = [refresh]
navigationController?.isToolbarHidden = false
}
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
title = webView.title
}
}
Here is the Amazon affiliate link that I have in my HTML:
<a target="_blank" href="https://rads.stackoverflow.com/amzn/click/com/B00KEBYK88" rel="nofollow noreferrer"><img border="0" src="https://ws-na.amazon-adsystem.com/widgets/q?_encoding=UTF8&MarketPlace=US&ASIN=B00KEBYK88&ServiceVersion=20070822&ID=AsinImage&WS=1&Format=_SL160_&tag=questionrs-20" ></a><img src="https://ir-na.amazon-adsystem.com/e/ir?t=questionrs-20&l=am2&o=1&a=B00KEBYK88" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" />
Note that it has an img tag:
<img border="0" src="https://ws-na.amazon-adsystem.com/widgets/q?_encoding=UTF8&MarketPlace=US&ASIN=B00KEBYK88&ServiceVersion=20070822&ID=AsinImage&WS=1&Format=_SL160_&tag=questionrs-20" >
If I put this img tag directly in my HTML the image is still not shown via the WKWebView in the app (but shows fine if I open the website in any browser directly)
If I open the image src in the browser it is converted to:
https://images-na.ssl-images-amazon.com/images/I/41ZIpVTW8-L._SL160_.jpg
And, if I put this new URL in the src, WKWebView can display it.
Is there any possibility to have WKWebView display the original image URL?