84 lines
2.1 KiB
Swift
84 lines
2.1 KiB
Swift
//
|
|
// 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"
|
|
|
|
@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
|
|
}
|
|
|
|
|
|
}
|