Help Center Manage Your Account Ad Tag

How do I display mobile ads using Apple iOS WKWebView?

For mobile ad serving to display ads in native Apple iOS applications, you can use WKWebView.

Sample Code

import UIKit
import WebKit

class ViewController: UIViewController , WKNavigationDelegate {

var webView : WKWebView!

override func viewDidLoad() {
  super.viewDidLoad()

  let adreq = "https://g.adspeed.net/ad.php?do=html&zid=xxxx..."
  let url = NSURL(string: adreq)
  let request = NSURLRequest(URL: url!)

  webView = WKWebView(frame: self.view.frame)
  webView.navigationDelegate = self
  webView.loadRequest(request)

  self.view.addSubview(webView)
  self.view.sendSubviewToBack(webView)
}

override func didReceiveMemoryWarning() {
  super.didReceiveMemoryWarning()
}

// WKNavigationDelegate

func webView(webView: WKWebView, didFailProvisionalNavigation navigation: WKNavigation!, withError error: NSError) {
  print(error.localizedDescription)
}
func webView(webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation!) {
  print("Loading")
}
func webView(webView: WKWebView, didFinishNavigation navigation: WKNavigation!) {
  print("Loaded")
}

}

Other Articles in Ad Tag

This section describes the ad tag (serving code) with basic and advanced settings. It includes common ad serving setup instructions and answers frequently asked questions when integrating the ad tag into your site, blog or app.

Cannot find an answer for your question? Ask our Customer Care team

Related