KlarnaStandaloneWebView is a new component embedded in the KlarnaMobileSDK to provide an easier integration way to enable Klarna features inside your app. It is a "WebView" with some modifications to allow Klarna to show and render content keeping the native feel of the app.
In this step-by-step guide you will learn how to integrate the KlarnaStandaloneWebView into your iOS app.
In order to display the KlarnaStandaloneWebView it needs to be instantiated using any of the available initializers with their respective parameters and then added to the view hierarchy.
By default the size of the KlarnaStandaloneWebView is zero (0), so it is up to you to handle the final size of the view, preferably using constraints.
Important: The KlarnaStandaloneWebView can not be instantiated using the interface builder, either through storyboards or XIB files, doing so will result in a crash.
To initialize the KlarnaStandaloneWebView you can pass the following parameters through the initialisers available:
Param | Type | Description |
---|---|---|
returnURL | URL | URL schema as defined in your app’s Plist to return from external applications. |
eventHandler | KlarnaEventHandler | A listener that will receive events from the SDK. |
environment | KlarnaEnvironment | Initialises the SDK with the specified Environment. For possible values check KlarnaEnvironment |
region | KlarnaRegion | Initializes the SDK with a specified Region. For possible values check KlarnaRegion. |
As previously mentioned, the KlarnaStandaloneWebView can be perceived as a specialized WKWebView developed specifically for displaying Klarna-related content. Consequently, it inherits many methods and properties from the standard WebView with the addition of some Klarna-specific methods and properties.
In essence, this means that while the KlarnaStandaloneWebView functions similarly to a typical WebView and maintains its broad functionality, it also includes certain distinct features that cater specifically to the Klarna content, enhancing its usability and performance within a Klarna context.
Since the KlarnaStandaloneWebView is an enhanced "WebView" some of the methods available are equivalent to those found in a WKWebView class. Please be aware this list is not exhaustive.
For example:
Adding javascript or user scripts to the KlarnaStandaloneWebView is also possible using any of the available methods for it.
For example:
Note: Depending on the iOS version some methods could be unavailable.
For navigation requests validation or related, the KlarnaStandaloneWebView exposes a delegate which conforms to the KlarnaStandaloneWebViewDelegate protocol which is a combination of the WKNavigationDelegate and the WKUIDelegate protocols.