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
.
UIWebView
For 1. Set the web view delegate
class ViewController: UIViewController{
override func viewWillAppear(_ animated: Bool) {
// ...
webView.delegate = self
}
}
shouldStartLoadWith
method
2. Implement the 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;
}
}
}
WKWebView
For 1. Set the web view navigation delegate
class ViewController: UIViewController{
override func viewWillAppear(_ animated: Bool) {
// ...
webView.navigationDelegate = self
}
}
decidePolicyFor
method
2. Implement the 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)
}
}
}