-
From Project Navigator pane Select you project -> Select your project in the left pane (not target) -> Select Package Dependencies tab
-
Enter
https://github.com/vuukle/ios-widgets-vuukle.gitURL in search field on top right corner. -
Select
Up To Next Major Versionand select version1.1.3 -
Click
Add Packagebutton. -
Import
Vuukleto yourViewController.swiftfile// Vuukle SDK import VuukleWidget -
Initialize
VuukleManagerclass passing viewcontroller and publisher key pairslet publisherKey = PublisherKeyPair(privateKey: "bd3a64e4-7e19-46b2-****-********", publicKey: "664e0b85-5b2c-4881-****-********") let vuukleManager = VuukleManager(viewController: self, publisherKeyPair: publisherKey)
-
Create views of type
VuukleView(from xib, storyboard or programmatically) that should show content of your URLslet vuukleView = VuukleView()
-
Load the Vuukle view by using the
vuukleManager.loadfunction, passing in the necessary parameters as shown below and add color parameter to the load function to allow for changing the background color if needed.vuukleManager.load(on: vuukleView, url: URL(string: "{vuukle_widget_uri}")!, backgroundColor: "#FFFF00")
The
vuukle_widget_uriparameter should be replaced with one of the following values, corresponding to the desired Vuukle platform:• Quizzly Platform: Enable quizzes and interactive content.
URI:
https://cdn.vuukle.com/amp-quiz.html• Commenting Platform: Enable a commenting system for user engagement.
URI:
https://cdn.vuukle.com/amp.html• Reactions (Emotes) Platform: Allow users to express their reactions to content.
URI:
https://cdn.vuukle.com/amp-emotes.html• Social Share Bar Platform: Integrate social media sharing functionality.
URI:
https://cdn.vuukle.com/amp-sharebar.htmlWhen loading the view, make sure to incorporate the following dynamic query parameters into the URI:
•
{HOST}: Your domain name without "www." or "https://" (e.g., example.com).•
{CANONICAL_URL}: The canonical URL of the page.•
{ARTICLE_ID}: Unique alphanumeric ID for the article page.•
{APIKEY}: Your Vuukle API key, which can be found in your Vuukle dashboard.•
{ARTICLEIMAGEURL}: Link to the article's image.•
{ARTICLE_TITLE}: The title of the article.For instance, the URI with dynamic parameters could look like this:
https://cdn.vuukle.com/amp-quiz.html?url=CANONICAL_URL&host=HOST&id=ARTICLE_ID&apiKey=YOUR_APIKEY&title=ARTICLE_TITLE&img=ARTICLE_IMAGE -
SSO Functionality For SSO login use:
vuukleManager.ssoLogin(token: "token here")
For SSO logout use"
vuukleManager.ssoLogout()
Add error listeners using public var addErrorListener: ((VuukleExceptions) -> Void)?
vuukleManager.addErrorListener = { exception in
switch exception {
case .didFailProvisionalNavigation(let error):
print("Error:", error)
case .failedToLoadURL(let url, let error):
print("URL and Error:", url, error)
@unknown default:
fatalError()
}
}See full list of exceptions in VuukleExceptions enum.
Use public var addSSOExceptionsListener: ((SSOExceptions) -> Void)? to catch SSO login/logout exceptions
vuukleManager.addSSOExceptionsListener = { exception in
switch exception {
case .emptyPublisherKeyPair(let message):
print("Error Message:", message)
case .authModelEncodingError(let error):
print("Error", error)
@unknown default:
print("Other exceptions", exception)
}
}See full list of exceptions in SSOExceptions enum.
Listen to events emitted from webview by adding listeners on vuukleManager.newEvent. If you did not set event listener, by default all events will be handled by VuukleManager
vuukleManager.newEvent.talkOfTheTownListener = { [weak self] url in
print("talkOfTheTown URL - ", url)
}
vuukleManager.newEvent.whatsOnYourMindListener = { [weak self] url in
print("whatsOnYourMind URL - ", url)
}
vuukleManager.newEvent.onSignInButtonClicked = { [weak self] in
print("onSignInButtonClicked URL - ", "")
}
vuukleManager?.newEvent.onLoadMoreArticlesButtonClicked = {[weak self] in
print("onLoadMoreArticlesButtonClickedL - ")
}
vuukleManager?.newEvent.onLoadMoreCommentsButtonClicked = {[weak self] in
print("onLoadMoreCommentsButtonClicked - ")
}
vuukleManager?.newEvent.pageFullyLoadedListener = { [weak self] url in
print("pageFullyLoadedListener URL - \(url)")
}See full list in NewEventListener class.