A request can e executed synchronously and asynchronously:
Synchronous requests. They return values after method execution.
Asynchronous requests. They return no value and the application moves to the next method. The response is generated as soon as available.
To get table data without loading to database by means of synchronous and asynchronous requests, create the HHFWTableRetry application, which uses framework methods:
| Method name | Brief description |
| initWithCredentials (_: host: environment: project: device:) | The method initializes the framework. |
| auth (_: password:) | The method authenticates the user by login and password. |
| setDownloadPath(_:) | The method sets the path to the folder in the mobile application directory, which will store resource files in the current downloading state. |
| useDownload(_:) | The method determines whether resource downloading is resumed. NOTE. The application code contains the tableStream/tableStreamAsync method, for which the TableCallParams auxiliary class is determined with the retryCount and retryIntervalSec properties. |
| table (_: transactionID: tableCallParams: handler:) | The method executes asynchronous request and returns resource table data without loading to database. |
| tableAsync (_: transactionID: tableCallParams: handler:) | The method executes asynchronous request and returns resource table data without loading to database. |
Auxiliary method:
| Method name | Brief description |
| getURL (forFolder:) | The method returns URL for the folder with the specified name in the Documents folder. Type of returned data: URL |
The HHFWTableRetry application includes one screen, the UITextView text view, and the UIButton button:
Request Table. Synchronous or asynchronous request for getting table data without loading to database.
NOTE. When the application is initialized, authentication is executed, the button is not available. If the authentication is executed successfully, the button is available and the text box display the text "Authentication success".
To execute the example, click the Request Table button. Clicking the button initializes a request to resource. The mobile platform server returns corresponding table data without loading to database.

Application code with synchronous request execution:
import UIKit
class ViewController: UIViewController {
// Determine output variables
@IBOutlet weak var resultTextView: UITextView!
@IBOutlet weak var tableRequestButton: UIButton!
// Redetermine method
override func viewDidLoad() {
super.viewDidLoad()
self.deactivateButtons()
self.initializeFramework()
self.auth {
self.activateButtons()
self.resultTextView.text = "Authentication success"
}
}
// Set method that will be executed on button click
@IBAction func tableRequestPressed(_ sender: UIButton) {
self.tableRequest { (jsonResult) in
self.resultTextView.text = String(format: "%@", jsonResult)
}
}
// Initialize framework
private func initializeFramework() {
let apiVersion: String = "v1"
let host: String = "http://testmasterfmp.fsight.cloud/"
let environment: String = "Leonid_environment"
let project: String = "Leonid_project"
let device: String = (UIDevice.current.identifierForVendor?.uuidString)!
HHFWController.sharedInstance().initWithCredentials(
apiVersion,
host: host,
environment: environment,
project: project,
device: device
)
}
// Execute authentication
private func auth(completion: @escaping ()->()) {
let username: String = "Leonid"
let password: String = "123123"
HHFWController.sharedInstance().auth(username, password: password){ (jsonResult) in
if let jsonDict = jsonResult as? NSDictionary,
let status = jsonDict["status"] as? String, status == "ok" {
print("Auth success")
completion()
} else {
print("Auth error")
}
}
}
private func setResumingDownload(_ value: Bool) {
let path = self.getURL(forFolder: "DownloadPath").path
HHFWController.sharedInstance().setDownloadPath(path)
HHFWController.sharedInstance().useDownload(value)
}
// Execute the Table request
private func tableRequest(completion: @escaping (NSDictionary)->()) {
let resourceName = "test_resource"
let tableCallParams = TableCallParams(defaultProperty: ())
tableCallParams?.retryCount = 10
tableCallParams?.retryIntervalSec = 1
HHFWController.sharedInstance().table(resourceName, transactionID: nil, tableCallParams: tableCallParams) { (jsonResult) in
if let jsonDict = jsonResult as? NSDictionary,
let status = jsonDict["status"] as? String, status == "ok" {
print("Table request success")
completion(jsonDict)
} else {
print("Table request error")
}
}
}
// Set methods for displaying application user interface elements
private func deactivateButtons() {
self.tableRequestButton.isEnabled = false
}
private func activateButtons() {
self.tableRequestButton.isEnabled = true
}
// Call auxiliary classes
private func getURL(forFolder folderName: String) -> URL {
let paths: [URL] = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)
let folderURL: URL = paths[0].appendingPathComponent(folderName, isDirectory: true)
return folderURL
}
}
Application code with asynchronous request execution:
import UIKit
class ViewController: UIViewController {
// Determine output variables
@IBOutlet weak var resultTextView: UITextView!
@IBOutlet weak var tableRequestButton: UIButton!
// Redetermine method
override func viewDidLoad() {
super.viewDidLoad()
self.deactivateButtons()
self.initializeFramework()
self.auth {
self.activateButtons()
self.resultTextView.text = "Authentication success"
}
}
// Set method that will be executed on button click
@IBAction func tableRequestPressed(_ sender: UIButton) {
self.tableRequest { (jsonResult) in
self.resultTextView.text = String(format: "%@", jsonResult)
}
}
// Initialize framework
private func initializeFramework() {
let apiVersion: String = "v1"
let host: String = "http://testmasterfmp.fsight.cloud/"
let environment: String = "Leonid_environment"
let project: String = "Leonid_project"
let device: String = (UIDevice.current.identifierForVendor?.uuidString)!
HHFWController.sharedInstance().initWithCredentials(
apiVersion,
host: host,
environment: environment,
project: project,
device: device
)
}
// Execute authentication
private func auth(completion: @escaping ()->()) {
let username: String = "Leonid"
let password: String = "123123"
HHFWController.sharedInstance().auth(username, password: password){ (jsonResult) in
if let jsonDict = jsonResult as? NSDictionary,
let status = jsonDict["status"] as? String, status == "ok" {
print("Auth success")
completion()
} else {
print("Auth error")
}
}
}
private func setResumingDownload(_ value: Bool) {
let path = self.getURL(forFolder: "DownloadPath").path
HHFWController.sharedInstance().setDownloadPath(path)
HHFWController.sharedInstance().useDownload(value)
}
// Execute the TableAsync request
private func tableRequest(completion: @escaping (NSDictionary)->()) {
let resourceName = "test_resource"
let tableCallParams = TableCallParams(defaultProperty: ())
tableCallParams?.retryCount = 10
tableCallParams?.retryIntervalSec = 1
HHFWController.sharedInstance().tableAsync(resourceName, transactionID: nil, tableCallParams: tableCallParams) { (jsonResult) in
if let jsonDict = jsonResult as? NSDictionary,
let status = jsonDict["status"] as? String, status == "ok" {
print("Table request success")
completion(jsonDict)
} else {
print("Table request error")
}
}
}
// Set methods for displaying application user interface elements
private func deactivateButtons() {
self.tableRequestButton.isEnabled = false
}
private func activateButtons() {
self.tableRequestButton.isEnabled = true
}
// Call auxiliary classes
private func getURL(forFolder folderName: String) -> URL {
let paths: [URL] = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)
let folderURL: URL = paths[0].appendingPathComponent(folderName, isDirectory: true)
return folderURL
}
}
See also:
Examples of iOS Framework Use | Examples of Working with Resources