// // MainViewController.swift // Runner // // Created by ZiKambrani on 26/03/1442 AH. // import UIKit import NVActivityIndicatorView class MainViewController: UIViewController { @IBOutlet weak var lblLoadingText: UILabel! @IBOutlet weak var loading: NVActivityIndicatorView! override func viewDidLoad() { super.viewDidLoad() print(loading) } func createBridge(flutterViewController:FlutterViewController){ let connectHMGGuestWifi = FlutterMethodChannel(name: "HMG-Platform-Bridge",binaryMessenger: flutterViewController.binaryMessenger) connectHMGGuestWifi.setMethodCallHandler { (methodCall, result) in if methodCall.method == "connectHMGGuestWifi"{ self.connectWifi(result: result) }else if methodCall.method == "loading"{ self.showLoading(flutterMethodCall: methodCall) }else{ } print("") } } // Connect HMG-Guest Wifi and Internet func connectWifi(result: @escaping FlutterResult){ showLoading(message: "Connecting...") HMG_GUEST.shared.connect { (status, message) in result(status ? 1 : 0) self.showLoading(false); if status{ self.showMessage(title:"Congratulations", message:message) }else{ self.showMessage(title:"Ooops,", message:message) } } } // Loading/Progress private func showLoading(flutterMethodCall:FlutterMethodCall){ if let args = flutterMethodCall.arguments as? [Any], let message = args.first as? String, let show = args.last as? Bool{ showLoading(message: message, show) }else{ assert(true, "Missing or invalid arguments (Must have two argument 'String at 0' and Boolean at 1)") } } func showLoading(message:String = "Please wait...", _ show:Bool = true){ DispatchQueue.main.async { if show{ self.lblLoadingText.text = message self.loading.superview?.isHidden = false self.loading.startAnimating() }else{ self.lblLoadingText.text = "" self.loading.superview?.isHidden = true self.loading.stopAnimating() } } } // Message Dailog func showMessage(title:String, message:String){ DispatchQueue.main.async { let alert = UIAlertController(title: title, message: message, preferredStyle: .alert ) alert.addAction(UIAlertAction(title: "OK", style: .destructive, handler: nil)) self.present(alert, animated: true) { } } } // MARK: - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation override func prepare(for segue: UIStoryboardSegue, sender: Any?) { if let flutterVC = segue.destination as? MainFlutterVC{ flutterVC.root_view = self createBridge(flutterViewController: flutterVC) } } }