Files
Woka_Native_iOS/WOKA/Address/Controller/PaymentWebViewVC.swift

82 lines
2.5 KiB
Swift
Raw Normal View History

//
// PaymentWebViewVC.swift
// WOKA
//
// Created by MacBook Pro on 29/07/24.
//
import UIKit
import WebKit
class PaymentWebViewVC: UIViewController,WKNavigationDelegate {
@IBOutlet weak var webView: WKWebView!
var url : String?
override func viewDidLoad() {
super.viewDidLoad()
DispatchQueue.main.async {
Utilities.startProgressHUD()
}
if let url {
let link = URL(string:url)!
let request = URLRequest(url: link)
webView.load(request)
}
webView.navigationDelegate = self
//Observer to check the url changes
webView.addObserver(self, forKeyPath: "URL", options: .new, context: nil)
}
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
Utilities.dismissProgressHUD()
}
override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
if let key = change?[NSKeyValueChangeKey.newKey] {
print("observeValue \(key)") // url value
if let finalURL = key as? URL {
let endpoint = finalURL.lastPathComponent
var domain = String()
if #available(iOS 16.0, *) {
domain = finalURL.host() ?? ""
} else {
domain = finalURL.host ?? ""
}
if domain == "secure.ccavenue.com" && endpoint.lowercased() == "canceltransaction"{
Timer.scheduledTimer(withTimeInterval: 2.5, repeats: false) { _ in
self.dismiss(animated: true)
}
}
} else {
print("urlAny is not a String")
}
}
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
navigationController?.setNavigationBarHidden(false, animated: animated)
}
override func viewDidAppear(_ animated: Bool) {
self.navigationController?.setColor(color: .white)
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
self.navigationController?.setNavigationBarHidden(true, animated: animated)
}
override func viewDidDisappear(_ animated: Bool) {
super.viewDidDisappear(animated)
// Customize the navigation bar's appearance
self.navigationController?.setColor(color: .black)
}
}