// // RadioVC.swift // WOKA // // Created by MacBook Pro on 13/06/24. // import UIKit import WebKit class RadioVC: UIViewController, WKNavigationDelegate { @IBOutlet var webView: WKWebView! var url = "https://wokaland.com/admin/api/woka_fm" // var url = "https://s4.voscast.com:9161/stream" provide on 18th july // var url = "https://planetcast.radiowalla.in/radio.mp3" //url from 24th july @IBOutlet weak var backView: UIView! deinit { unloadWebView() } // WKNavigationDelegate methods func webView(_ webView: WKWebView, didFail navigation: WKNavigation!, withError error: Error) { print("Failed to load: \(error.localizedDescription)") } func webView(_ webView: WKWebView, didFailProvisionalNavigation navigation: WKNavigation!, withError error: Error) { print("Failed to start loading: \(error.localizedDescription)") } func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) { print("Finished loading") } override func viewDidLoad() { super.viewDidLoad() if #available(iOS 14.0, *) { webView.configuration.defaultWebpagePreferences.allowsContentJavaScript = true } else { // Fallback on earlier versions webView.configuration.preferences.javaScriptEnabled = true } let radioURL = URL(string: url)! let request = URLRequest(url: radioURL) webView.load(request) webView.navigationDelegate = self backView.addTapGesture { self.dismiss(animated: true) { self.unloadWebView() } } } override func viewDidDisappear(_ animated: Bool) { webView.stopLoading() } @IBAction func closeBtnTapped(_ sender: UIButton) { self.dismiss(animated: true) { self.unloadWebView() } } func unloadWebView() { // Cancel any ongoing navigation webView.stopLoading() // Set delegates to nil webView.navigationDelegate = nil webView.uiDelegate = nil // Remove from superview webView.removeFromSuperview() // Release the web view webView = nil } }