Skip to content

Integrate Vuukle in a native iOS app

The current iOS integration uses Vuukle’s mobile iframe URLs loaded inside a WKWebView. No SDK updates required — the web layer ships features and fixes automatically.

The iframe URLs

Comment widget

https://cdn.vuukle.com/amp.html?apiKey={APIKEY}&host={HOST}&id={ARTICLE_ID}&img={IMAGE}&title={TITLE}&url={URL}

Emote widget

https://cdn.vuukle.com/widgets/emotes.html?apiKey={APIKEY}&host={HOST}&articleId={ARTICLE_ID}&img={IMAGE}&title={TITLE}&url={URL}
ParamValue
apiKeyYour public API key
hostYour site host (no www., no https://)
id / articleIdUnique article ID
imgArticle image URL
titleArticle title
urlFull article URL (with scheme)

Minimum WKWebView setup

import WebKit
override func viewDidLoad() {
super.viewDidLoad()
let configuration = WKWebViewConfiguration()
let wkWebView = WKWebView(frame: view.bounds, configuration: configuration)
wkWebView.uiDelegate = self
view.addSubview(wkWebView)
if let url = URL(string: vuukleIframeURL) {
wkWebView.load(URLRequest(url: url))
}
}

Handle social auth popup windows

ViewController needs to conform to WKUIDelegate:

private var isPopUpAppeared = false
func webView(_ webView: WKWebView,
createWebViewWith configuration: WKWebViewConfiguration,
for navigationAction: WKNavigationAction,
windowFeatures: WKWindowFeatures) -> WKWebView? {
if navigationAction.targetFrame == nil {
let popup = WKWebView(frame: view.frame, configuration: configuration)
popup.uiDelegate = self
view.addSubview(popup)
isPopUpAppeared = true
return popup
}
return nil
}
func webViewDidClose(_ webView: WKWebView) {
if isPopUpAppeared {
webView.removeFromSuperview()
}
}

Handle “Report comment” confirm panel

func webView(_ webView: WKWebView,
runJavaScriptConfirmPanelWithMessage message: String,
initiatedByFrame frame: WKFrameInfo,
completionHandler: @escaping (Bool) -> Void) {
let alert = UIAlertController(title: nil, message: message, preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "Ok", style: .default) { _ in completionHandler(true) })
alert.addAction(UIAlertAction(title: "Cancel", style: .cancel ) { _ in completionHandler(false) })
present(alert, animated: true)
}

Log a user out

Clear cookies for the Vuukle host:

private func clearCookiesFromSpecificUrl(_ urlString: String) {
let storage = HTTPCookieStorage.shared
guard let url = URL(string: urlString) else { return }
storage.cookies(for: url)?.forEach { storage.deleteCookie($0) }
}

Reference app

Full sample: github.com/lesukk/vuukle_iOS_SDK (branch web_sdk_iOS)

Was this page helpful?
Help us improve — drop a note or open the dashboard.