GithubHelp home page GithubHelp logo

isabella232 / klarnamobilesdkdemo Goto Github PK

View Code? Open in Web Editor NEW

This project forked from klarna/klarnamobilesdkdemo

0.0 0.0 0.0 23.67 MB

Klarna Mobile SDK demo app for iOS

License: Apache License 2.0

Swift 59.51% HTML 39.41% Ruby 1.08%

klarnamobilesdkdemo's Introduction

KlarnaMobileSDK Demo

This demo shows how you can integrate KlarnaMobileSDK into your existing web views, UIWebView or WKWebView.

It loads a local harry.html file into webviews for demonstrations.

Run the demo app

This demo demonstrate how you can use Cocoapods to integrate KlarnaMobileSDK into your XCode project, this is included Podfile:

use_frameworks!

platform :ios, "10.0"

target "KlarnaMobileSDKDemo" do
   pod "KlarnaMobileSDK"
end

To run the demo app, just open KlarnaMobileSDKDemo.xcworkspace, click on Run.

Important steps during integration

There are a few important steps that you need to perform to have a successful integration:

  • Initialize KlarnaHybridSDK with a UIWebView or WKWebView, make sure providing a returnUrl and eventListener during the initialization.
	klarnaHybridSDK = KlarnaHybridSDK(webView: webView,
                                   returnUrl: URL(string: "your-app-scheme://")!,
                                   eventListener: self)
  • Implement WebView's delegate, call relavant KlarnaHybridSDK methods.

    • For UIWebView:

       func webViewDidFinishLoad(_ webView: UIWebView) {
           klarnaHybridSDK?.newPageWillLoad(in: webView)
       }
      
       func webView(_ webView: UIWebView,
                    shouldStartLoadWith request: URLRequest,
                    navigationType: UIWebView.NavigationType) -> Bool {
      
           return klarnaHybridSDK?.shouldFollowNavigation(withRequest: request) == true ? true : false
       }
    • For WKWebView:

       func webView(_ webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation!) {
           klarnaHybridSDK?.newPageWillLoad(in: webView)
       }
      
       func webView(_ webView: WKWebView,
                    decidePolicyFor navigationAction: WKNavigationAction,
                    decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {
      
           decisionHandler(klarnaHybridSDK?.shouldFollowNavigation(withRequest: navigationAction.request) == true ? .allow : .cancel)
       }
  • Implement KlarnaHybridSDKEventListener.

    func klarnaHybridSDKWillShowFullscreen(inWebView webView: KlarnaWebView, completion: () -> Void) {
        // Handle fullscreen transitions
        print("[KlarnaHybridSDK]: will show fullscreen")
        completion()
    }

    func klarnaHybridSDKDidShowFullscreen(inWebView webView: KlarnaWebView, completion: () -> Void) {
        // Handle fullscreen transitions
        print("[KlarnaHybridSDK]: did show fullscreen")
        completion()
    }

    func klarnaHybridSDKWillHideFullscreen(inWebView webView: KlarnaWebView, completion: () -> Void) {
        // Handle fullscreen transitions
        print("[KlarnaHybridSDK]: will hide fullscreen")
        completion()
    }

    func klarnaHybridSDKDidHideFullscreen(inWebView webView: KlarnaWebView, completion: () -> Void) {
        // Handle fullscreen transitions
        print("[KlarnaHybridSDK]: did hide fullscreen")
        completion()
    }

    func klarnaHybridSDKFailed(inWebView webView: KlarnaWebView, withError error: KlarnaMobileSDKError) {
        // Handle Klarna hybrid SDK related errors
        print("[KlarnaHybridSDK]: did get error: \(error.debugDescription)")
    }

klarnamobilesdkdemo's People

Contributors

gbanfalvikl avatar mkgithub avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.