Example of Mobile Platform Server Availability Check

To execute mobile platform server availability check, create the HHFWConnectionStatus application, which uses the framework method:

Method name Brief description
connectionStatus (_: handler:) The method checks mobile platform server availability.

The HHFWConnectionStatus application includes one screen, the UITextField text box, the UITextView text view, and UIButton button:

To execute the example:

  1. Enter server URL in the text box.

  2. Click the Check Connection Status button.

Clicking the button requests to execute mobile platform server availability check.

Application code:

import UIKit
 
class ViewController: UIViewController {
 
    // Determine output variables
    @IBOutlet weak var hostTextField: UITextField!
    @IBOutlet weak var checkConnectionButton: UIButton!
    @IBOutlet weak var resultTextView: UITextView!
 
    // Set method that will be executed on button click
    @IBAction func checkConnectionPressed(_ sender: UIButton) {
        sender.isEnabled = false
        self.checkConnection() { (jsonResult) in
            sender.isEnabled = true
            self.resultTextView.text = String(format: "%@", jsonResult)
        }
    }
 
    // Display result of checking mobile platform server availability
    private func checkConnection(completion: @escaping (NSDictionary)->()) {
        let host: String = self.hostTextField.text ?? ""
        HHFWController.sharedInstance().connectionStatus(host) { (jsonResult) in
            if let jsonDict = jsonResult as? NSDictionary,
                let status = jsonDict["status"] as? String, status == "ok" {
                print("Online")
                completion(jsonDict)
            } else {
                print("Offline")
            }
        }
    }
}

See. also:

Examples of iOS Framework Use