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}| Param | Value |
|---|---|
apiKey | Your public API key |
host | Your site host (no www., no https://) |
id / articleId | Unique article ID |
img | Article image URL |
title | Article title |
url | Full 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)
Related
Was this page helpful?
Help us improve — drop a note or open the dashboard.