Unico IDPay - DevCenter
HomepageAutenticaçãoAPI Reference
English
English
  • Introduction
  • ABOUT IDPAY
    • Unico ID Pay
    • Features
    • Use Cases
    • Chargeback
  • INTEGRATION
    • Overview
    • Authentication
      • Creating a Service Account
      • Preparing to make an authenticated request to the API
      • Additional resources
        • Example in JavaScript
        • Authentication Errors
        • Postman Collection
    • APIs
      • API Reference
        • Payment transactions
        • Chargeback
        • Credit card onboarding
      • Errors
      • Enumerated
    • Webhook
    • Controlling the experience
      • Overview
      • Requirements
      • Mobile
        • Android
        • Flutter
        • iOS
          • WKWebView
          • ASWebAuthenticationSession
      • Web
        • SDK
        • Redirect (deprecated)
    • Customizations
  • HELP & FAQ
    • FAQ
    • Best communication practices
    • Help Center
Powered by GitBook

Copyright © 2024 unico. All rights reserved.

On this page

Was this helpful?

Export as PDF
  1. INTEGRATION
  2. Controlling the experience
  3. Mobile
  4. iOS

WKWebView

In this section, you will find how to implement the webview on iOS using WKWebView.


For the iOS usage scenario, using WKWebView is one of the recommended approaches.

After creating the transaction and obtaining the transaction link, the following implementation is recommended:

  • In your common flow (which includes IDPay), you will open the WKWebView with the link generated via the API;

  • You can customize this opening as needed for your app;

  • You will monitor if the URL has changed (to the redirectUrl) and then close the WKWebView.

Opening a WKWebView is quite simple:

import UIKit
import WebKit
import SafariServices

var webView: WKWebView!

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view.
    self.view.backgroundColor = .white
}

@IBAction func open(_ sender: Any) {
    createWKWebViewFull()
}

func createWKWebViewFull() {
    webView = WKWebView(frame: self.view.bounds, configuration: getWKWebViewConfiguration())
    webView.navigationDelegate = self
    view.addSubview(webView)
    self.loadUrl()
}

func loadUrl() {
    if let url = URL(string:"<URL_TO_LOAD>") {
        webView.load(URLRequest(url: url))
        webView.allowsBackForwardNavigationGestures = true
    }
}

private func getWKWebViewConfiguration() -> WKWebViewConfiguration {
    let config = WKWebViewConfiguration()
    config.allowsInlineMediaPlayback = true
    config.mediaTypesRequiringUserActionForPlayback = []

    return config
}

To control when to close the WKWebView, this can be done as follows:

func webView(_ webView: WKWebView, didCommit navigation: WKNavigation!) {
    if let currentURL = webView.url {
        print("URL changed to: \(currentURL.absoluteString)")
        if currentURL.absoluteString == "<URL_TO_OBSERVER>" {
            closeWebView()
        }
    }
}

@objc func closeWebView() {
    DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
        self.webView.removeFromSuperview()
    }
}

Example of how it should look in the app:

It is necessary to have some permissions to function correctly, such as:

  • Camera

  • Geolocation

To learn more, we recommend reading the following articles and documentation:


PreviousiOSNextASWebAuthenticationSession

Last updated 5 months ago

Was this helpful?

To access the official documentation, click .

Still need help?

Didn't find something or still need help? If you're already a client or partner, you can reach out through our .

here
​
Help Center