Skip to content

How to handle HelaPay links inside UIWebView and WKWebView

Notifications You must be signed in to change notification settings

PayHereDevs/helapay-link-handler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Handling හෙළPay Links

Setup

Clone this repo.

git clone https://github.com/PayHereDevs/helapay-link-handler.git

To properly handle හෙළPay Links in your iOS WebView project, you will need the following helper class.

helapay-links/HelaPayLinkHandler.swift

Copy it into your Xcode project. Follow one of the following steps, depending on whether you use UIWebView or WKWebView.

For UIWebView

1. Set the web view delegate
class ViewController: UIViewController{
    override func viewWillAppear(_ animated: Bool) {
        // ...

        webView.delegate = self
    }
}
2. Implement the shouldStartLoadWith method
extension ViewController: UIWebViewDelegate{
    func webView(_ webView: UIWebView, shouldStartLoadWith request: URLRequest, navigationType: UIWebView.NavigationType) -> Bool {

        // Important check for external suffix
        if let url = request.url, url.absoluteString.hasSuffix("#HKexternal") {
            HelaPayLinkHandler().handleHelaPayLink(url)
            return false
        }
        else{
            return true;
        }

    }
}

For WKWebView

1. Set the web view navigation delegate
class ViewController: UIViewController{
    override func viewWillAppear(_ animated: Bool) {
        // ...

        webView.navigationDelegate = self
    }
}
2. Implement the decidePolicyFor method
extension ViewController: WKNavigationDelegate{
    func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {
        
        // Important check for external suffix
        if let url = navigationAction.request.url, url.absoluteString.hasSuffix("#HKexternal") {
            HelaPayLinkHandler().handleHelaPayLink(url)
            decisionHandler(.cancel)
        }
        else{
            decisionHandler(.allow)
        }
    }
}

About

How to handle HelaPay links inside UIWebView and WKWebView

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages