قالب وردپرس درنا توس
Home / IOS Development / ios – WKWebView and Amazon Affiliate image src

ios – WKWebView and Amazon Affiliate image src



I use linked image links to amazon on my site which is then converted to an app using WKWebView in Swift 4.

Affiliate link to Amazon works perfectly if I access the web page directly from Safari or some other browser. But the image does not appear in the app that uses WKWebView: a small question mark icon appears instead, and when I click on the small icon, the right amazon link opens.

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
la url = URL (string: "http: // myurl /")! webView.load (URLRequest (url: url)) // 2 la update = UIBarButtonItem (barButtonSystemItem: .refresh, target: webView, action: #selector (webView.reload)) toolbarItems = [refresh] navigation controller? .isToolbarHidden = false } func webView (_ webView: WKWebView, didFinish navigation: WKNavigation!) { title = webView.title } }

Here is the Amazon affiliate link that I have in my HTML:

     

Note that it has an img code:

  

If I put this img tag directly in the HTML, the image will still not be displayed via WKWebView in the app (but show well if I open the site in a 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 src, WKWebView can display it.

Is there any way to get WKWebView to display the original URL of the image?


Source link