Examples of iOS Framework Use

The examples consider applications that include one screen and several buttons. Each button implements one simple action and executes a framework method. All considered applications describe basic functions and enable the user to quickly get started with the framework.

Each application must contains an authentication method. If a local database is used, open a connection and load resources schemes.

To create an example using authentication method, see the Example of Authentication at Mobile Platform Server section.

Examples of working with:

The example of source code for preparing application to work with mobile platform server using a local database:

let apiVersion: String = "v1"
let host: String = "http://testmasterfmp.fsight.cloud/"
let environment: String = "Leonid_environment"
let project: String = "Leonid_project"
let application: String = "app"
let device: String = (UIDevice.current.identifierForVendor?.uuidString)!
 
HHFWController.sharedInstance().initWithCredentials(
    apiVersion,
    host: host,
    environment: environment,
    project: project,
    application: application,
    device: device
)
 
let userName: String = "Leonid"
let password: String = "123123"
let databaseName = "database.sqlite"
let paths: [URL] = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)
let fullDatabaseURL: URL = paths[0].appendingPathComponent(databaseName)
 
// Authentication
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")
        // Open database connection
        if HHFWController.sharedInstance().openBase(fullDatabaseURL.path, key: "") {
            print("Open base success")
            // Load resources schemes
            HHFWController.sharedInstance().resources(databaseName, handler: { (jsonResult) in
                if let jsonDict = jsonResult as? NSDictionary,
                    let status = jsonDict["status"] as? String, status == "ok" {
                    print("Resource scheme success")
                }
            })
        }
    }
}

See also:

iOS Framework | Initializing iOS Framework | Describing iOS Framework Methods