To develop a mobile application, requests to mobile platform server use iOS framework methods of the HHFWController main class.
The most of methods are executed asynchronously in a background stream. To display request execution result, send the "hander" closure of the HHFWCompletionHandler? type to the method that is automatically called in the main stream after method execution.
NOTE. Before executing methods execute authentication on a mobile platform server by login and password or with password change. To work with a local database and resources, open connection and load resources schemes, otherwise methods will call the "handler" closure with the Null parameter.
Authenticate user by login and password (auth)
The auth method authenticates the user by login and password.
NOTE. Before executing the method make sure that data source credentials are added in the project.
HHFWController.sharedInstance().auth(_ login: String, password: String, handler: HHFWCompletionHandler? = nil)
Input parameters:
Parameter | Data type | Description |
login | String | User login. |
password | String | User password. |
handler | HHFWCompletionHandler? | Callback function executed after query is completed. It is set to nil by default. |
Example:
let userName: String = "user"
let password: String = "password"
HHFWController.sharedInstance().auth(userName, password: password){ (jsonResult: Any?) in
// This block can be used to process response from jsonResult mobile platform server that is presented as JSON
// jsonResult contains authentication status, error description and other information
// This block can also be used to open database connection
}
After executing the method a user token is obtained. The token is used in each request to a mobile platform server.
User authentication with password change (auth)
The auth method authenticates user with password change. Executing the method requires the current user login and password, new password, and new password confirmation.
NOTE. Before executing the method make sure that data source credentials are added in the project.
HHFWController.sharedInstance().auth(_ login: String, password: String, newPassword: String, confirmPassword confirm: String, handler: HHFWCompletionHandler? = nil)
Input parameters:
Parameter | Data type | Description |
login | String | User login. |
password | String | User password. |
newPassword | String | New user password. |
confirmPassword | String | Confirm new user password. |
handler | HHFWCompletionHandler? | Callback function executed after query is completed. It is set to nil by default. |
Example:
let userName: String = "user"
let password: String = "password"
let newPassword: String = "newPassword"
let confirmPassword: String = "newPassword"
HHFWController.sharedInstance().auth(userName, password: password, newPassword: newPassword, confirmPassword: confirmPassword){ (jsonResult: Any?) in
// This block can be used to process response from jsonResult mobile platform server that is presented as JSON
// jsonResult contains authentication status, error description and other information
// This block can also be used to open database connection
}
A new user token is obtained after executing the method. The token is used in each request to a mobile platform server.
Checking LDAP Use by SSL Protocol (setSSLChecks)
The setSSLChecks method determines whether LDAP is used by SSL protocol on connection to mobile platform server.
HHFWController.sharedInstance().setSSLChecks(_ enabled: Bool)
Input parameters:
Parameter | Data type | Description |
enabled | Bool | Indicates whether LDAP is used by SSL protocol:
|
Example:
let isCheckSSLOn: Bool = true
HHFWController.sharedInstance().setSSLChecks(isCheckSSLOn)
Cancel authentication (unAuth)
The unAuth method cancels user authentication.
HHFWController.sharedInstance().unAuth()
The use of methods is given in the Examples of Authentication on Mobile Platform Server section.
Mobile platform server availability check (connectionStatus)
The connectionStatus method checks mobile platform server availability.
HHFWController.sharedInstance().connectionStatus(_ host: String, handler: HHFWCompletionHandler? = nil)
Input parameters:
Parameter | Data type | Description |
host | String | Mobile platform server URL. |
handler | HHFWCompletionHandler? | Callback function executed after query is completed. It is set to nil by default. |
Example:
let host: String = "https://<IP address or DNS server name>"
HHFWController.sharedInstance().connectionStatus(host){ (jsonResult: Any?) in
// This block can be used to handle the response of the jsonResult mobile platform server that is presented as json
// jsonResult contains authentication status, error description and other information
// This block can also be used to open database connection
}
The method use is given in the Example of Mobile Platform Server Availability Check section.
Open or create a database (openBase)
The openBase method opens connection with the database at the specified path.
When the connection is established, data can be written to local database. If the database is not found at the specified path, a new database is created, with which a connection is established.
NOTE. Create a database in the Documents application folder. Framework methods address to the database of this folder.
HHFWController.sharedInstance().openBase(_ pathBase: String, key: String) -> Bool
Input parameters:
Parameter | Data type | Description |
pathBase | String | The path to the database server relative to the root directory of the mobile device file system. |
key | String | Database encryption key. |
Example:
let paths: [URL] = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)
let fullDatabaseURL: URL = paths[0].appendingPathComponent("database.sqlite")
let databaseKey: String = "key" // if encryption is not needed, then key = ""
let success = HHFWController.sharedInstance().openBase(fullDatabaseURL.path, key: databaseKey)
After executing the method a connection is opened with the local database, and True is returned, otherwise False is returned.
Change database encryption key (rekeyBase)
The rekeyBase method changes local database encryption key.
HHFWController.sharedInstance().rekeyBase(_ pathBase: String, newKey key: String) -> Bool
Input parameters:
Parameter | Data type | Description |
pathBase | String | The path to the database server relative to the root directory of the mobile device file system. |
newKey | String | New database encryption key. |
The method returns True if encryption key is successfully changed, otherwise it returns False.
Example:
let databaseName: String = "database.sqlite"
let newKey: String = "newKey"
HHFWController.sharedInstance().rekeyBase("/Documents/\(databaseName)", newKey: newKey)
NOTE. Before changing encryption key open database using the openBase method.
The query method sends SQL query to local database.
HHFWController.sharedInstance().query(_ base: String?, query: String) -> String?
Input parameters:
Parameter | Data type | Description |
base | String? | The path to the database server relative to the root directory of the mobile device file system. |
query | String | SQL query. |
Table name format in local database: <resourceName>_<hash>_<tableName>, where:
resourceName. Name of resource.
hash. Hash sum calculated based on request parameters. Parameters are specified in the request to write data to database using the "data" property of the *CallParams class
tableName. Table name.
The method returns request execution result as JSON.
Example:
let jsonResult: String? = HHFWController.sharedInstance().query("/Documents/\(databaseName)", query: "SELECT * FROM TableNameInDatabase WHERE `key` = 'value'")
Get table names (getTablesName)
The getTablesName method returns table names if local caching is used on writing to database.
HHFWController.sharedInstance().getTablesName(_ databasePath: String, resourceName resource: String, requestParams params: String, tableName table: String?) -> String?
Input parameters:
Parameter | Data type | Description |
databasePath | String | The path to the database file relative to the application root directory. For example, the path to the database.sqlite database file located in the Documents folder: /Documents/database.sqlite. |
resourceName, resource | String | Name of resource. |
requestParams, params | String | JSON string with parameters, with which query was executed. |
tableName, table | String? | Table name on server. It is used to get a specific table in a multi-table resource. |
If local caching is not used, tables are not found. To create a table name manually, use resource name and table name as follows: <resourceName>_<tableName>, where:
resourceName. Name of resource.
tableName. Table name.
Example:
let databaseName: String = "database.sqlite"
let resourceName: String = "ResourceName"
let params: String = "{}"
let tableName: String = "TableName"
let jsonResult: String! = HHFWController.sharedInstance().getTablesName("/Documents/\(databaseName)", resourceName: resourceName, requestParams: "", tableName: tableName)
After executing the example the list of all table names is obtained.
Delete tables from database (dropCache)
The dropCache method deletes tables from database.
HHFWController.sharedInstance().dropCache(_ databasePath: String, resourceName resource: String, requestParams params: String) -> String?
Input parameters:
Parameter | Data type | Description |
databasePath | String | The path to the database file relative to the application root directory. For example, the path to the database.sqlite database file located in the Documents folder: /Documents/database.sqlite. |
resourceName, resource | String | Name of resource. |
requestParams, params | String | JSON string with parameters, with which query was executed. |
The method returns request execution result as JSON.
Example:
To clear cache in a local database, delete tables that were created after queries with specifying specific parameters:
let databaseName: String = "database.sqlite"
let resourceName: String = "ResourceName"
let params: String = "{}"
let jsonResult: String! = HHFWController.sharedInstance().dropCache("/Documents/\(databaseName)", resourceName: resourceName, requestParams: params)
To delete all *.sqlite files from the Documents folder in the application directory, use the request without specifying parameters:
HHFWController.sharedInstance().dropCache()
The closeBase method closes database connection.
HHFWController.sharedInstance().closeBase(_ pathBase: String) -> Bool
Input parameters:
Parameter | Data type | Description |
pathBase | String | The path to the database server relative to the root directory of the mobile device file system. |
The method returns True database connection is successfully closed, otherwise it returns False.
The method can be used if authentication is canceled.
The use of methods is given in the Examples of Working with Resources section.
Load resources scheme (resources)
The resources method gets schemes of available resources and automatically creates corresponding tables in the database. Before loading a resources scheme, a database connection opens similarly to the openBase method.
HHFWController.sharedInstance().resources(_ database: String?, password: String?, handler: HHFWCompletionHandler? = nil)
Input parameters:
Parameter | Data type | Description |
database | String? | Name of used database. NOTE. If the parameter is set to nil, the hhfw.sqlite default database is used on method execution. |
password | String? | Database encryption key. |
handler | HHFWCompletionHandler? | Callback function executed after query is completed. It is set to nil by default. |
Example:
let databaseName: String = "database.sqlite"
let databaseKey: String = "databaseKey"
HHFWController.sharedInstance().resources(databaseName, password: databaseKey){ (jsonResult: Any?) in
// This block can be used to handle response of the jsonResult mobile platform server that is presented as json
// jsonResult contains information about scheme request, server response and resources scheme
}
After executing the method, the resources scheme will be automatically written to the specified database. The specified database is searched or created in the Documents folder in the application directory.
Synchronous delta loading to database (deltaStream)
The deltaStream method synchronously loads delta to database.
NOTE. Before executing the method load resources scheme.
HHFWController.sharedInstance().deltaStream(_ resourceName: String, withCache: Bool, deltaStreamCallParams: DeltaStreamCallParams?, handler: HHFWCompletionHandler? = nil)
Input parameters:
Parameter | Data type | Description |
resourceName | String | Name of resource. |
withCache | Bool | Indicates whether table caching is used in a local database. |
deltaStreamCallParams | DeltaStreamCallParams? | An instance of the DeltaStreamCallParams class describing request parameters. |
handler | HHFWCompletionHandler? | Callback function executed after query is completed. It is set to nil by default. |
When an instance of the DeltaStreamCallParams class is initialized with defaultDb, the hhfw.sqlite name is used by default. If the searched database name differs, after initialization of DeltaStreamCallParams specify full path to the database using the dataBasePath property.
Example:
let resourceName: String = "ResourceName"
let isCached: Bool = true
let deltaStreamCallParams: DeltaStreamCallParams = DeltaStreamCallParams(defaultDb: ())
deltaStreamCallParams?.dataBasePath = fullDatabaseURL.path
HHFWController.sharedInstance().deltaStream(resourceName, withCache: isCached, deltaStreamCallParams: deltaStreamCallParams){ (jsonResult: Any?) in
// This block can be used to handle the jsonResult mobile platform server response in the json format
// jsonResult contains information about query, server response and query result
}
After executing the method the data delta is automatically synchronously written to the specified database according to the previously obtained scheme.
Asynchronous delta loading to database (deltaStreamAsync)
The deltaStreamAsync method asynchronously loads delta to database.
NOTE. Before executing the method load resources scheme.
HHFWController.sharedInstance().deltaStreamAsync(_ resourceName: String?, withCache: Bool, deltaStreamCallParams: DeltaStreamCallParams?, handler: HHFWCompletionHandler? = nil)
Input parameters:
Parameter | Data type | Description |
resourceName | String? | Name of resource. |
withCache | Bool | Indicates whether table caching is used in a local database. |
deltaStreamCallParams | DeltaStreamCallParams? | An instance of the DeltaStreamCallParams class describing request parameters. |
handler | HHFWCompletionHandler? | Callback function executed after query is completed. It is set to nil by default. |
When an instance of the DeltaStreamCallParams class is initialized with defaultDb, the hhfw.sqlite name is used by default. If the searched database name differs, after initialization of DeltaStreamCallParams specify full path to the database using the dataBasePath property.
Example:
let deltaStreamCallParams: DeltaStreamCallParams = DeltaStreamCallParams(defaultDb: ())
deltaStreamCallParams?.dataBasePath = fullDatabaseURL.path
let resourceName: String = "ResourceName" // resource name
let isCached: Bool = true
HHFWController.sharedInstance().deltaStreamAsync(resourceName, withCache: isCached, deltaStreamCallParams: deltaStreamCallParams){ (jsonResult: Any?) in
// This block can be used to handle response of the jsonResult mobile platform server that is presented as json
// jsonResult contains information about query, server response and query result
}
After executing the method the data delta is automatically synchronously written to the specified database according to the previously obtained scheme.
Synchronous table data loading to database (tableStream)
The tableStream method synchronously loads table data to database.
NOTE. Before executing the method load resources scheme.
HHFWController.sharedInstance().tableStream(_ resourceName: String, withCache: Bool, transactionID: String?, tableCallParams: RequestCallParams?, handler: HHFWCompletionHandler? = nil)
Input parameters:
Parameter | Data type | Description |
resourceName | String | Name of resource. |
withCache | Bool | Indicates whether table caching is used in a local database. |
transactionID | String? | Transaction identifier. NOTE. If the parameter is set to nil, a transaction will be unavailable to get its repeated result using the retryTableStream method because it will not be saved on the server. |
tableCallParams | RequestCallParams? | An instance of the RequestCallParams class describing query parameters. |
handler | HHFWCompletionHandler? | Callback function executed after query is completed. It is set to nil by default. |
When an instance of the RequestCallParams class is initialized with defaultDb, the hhfw.sqlite name is used by default. If the searched database name differs, after initialization of RequestCallParams specify full path to the database using the dataBasePath property.
Example:
let resourceName: String = "ResourceName"
let isCached: Bool = true
let requestCallParams: RequestCallParams = RequestCallParams(defaultDb: ())
requestCallParams?.dataBasePath = fullDatabaseURL.path
HHFWController.sharedInstance().tableStream(resourceName, withCache: isCached, transactionID: nil, tableCallParams: requestCallParams){ (jsonResult: Any?) in
// This block can be used to handle the jsonResult mobile platform server response in the json format
// jsonResult contains information about query, server response and query result
}
After executing the method table data is automatically synchronously written to the specified database according to the previously obtained scheme.
Table data can also be filtered. To filter data, specify query arguments in the query via sending the dictionary with arguments into the "args" parameter for the instance of the *CallParams class.
For details about filtering types, see the Method for Working with Table Resources section.
The example of request to get data filtered by values in columnName columns:
let requestCallParams: RequestCallParams = RequestCallParams(defaultDb: ())
requestCallParams?.dataBasePath = fullDatabaseURL.path
requestCallParams?.args = ["col_columnName1": value1, "col_columnName2": value2, ...]
Asynchronous table data loading to database (tableStreamAsync)
The tableStreamAsync method asynchronously loads table data to database.
NOTE. Before executing the method load resources scheme.
HHFWController.sharedInstance().tableStreamAsync(_ resourceName: String?, withCache: Bool, transactionID: String?, tableCallParams: RequestCallParams?, handler: HHFWCompletionHandler? = nil)
Input parameters:
Parameter | Data type | Description |
resourceName | String? | Name of resource. |
withCache | Bool | Indicates whether table caching is used in a local database. |
transactionID | String? | Transaction identifier. NOTE. If the parameter is set to nil, a transaction will be unavailable to get its repeated result using the retryTableStreamAsync method because it will not be saved on the server. |
tableCallParams | RequestCallParams? | An instance of the RequestCallParams class describing query parameters. |
handler | HHFWCompletionHandler? | Callback function executed after query is completed. It is set to nil by default. |
When an instance of the RequestCallParams class is initialized with defaultDb, the hhfw.sqlite name is used by default. If the searched database name differs, after initialization of RequestCallParams specify full path to the database using the dataBasePath property.
Example:
let resourceName: String = "ResourceName" // resource name
let isCached: Bool = true
let requestCallParams: RequestCallParams = RequestCallParams(defaultDb: ())
requestCallParams?.dataBasePath = fullDatabaseURL.path
HHFWController.sharedInstance().tableStreamAsync(resourceName, withCache: isCached, transactionID: nil, tableCallParams: requestCallParams){ (jsonResult: Any?) in
// This block can be used to handle the jsonResult mobile platform server response in the json format
// jsonResult contains information about query, server response and query result
}
After executing the method table data is automatically synchronously written to the specified database according to the previously obtained scheme.
Synchronous getting resource table data without loading to database (table)
The table method synchronously requests resource table data without loading to database.
HHFWController.sharedInstance().table(_ resourceName: String, transactionID: String?, tableCallParams: TableCallParams?, handler: HHFWCompletionHandler? = nil)
Input parameters:
Parameter | Data type | Description |
resourceName | String | Name of resource. |
transactionID | String? | Transaction identifier. NOTE. If the parameter is set to nil, a transaction will be unavailable to get its repeated result using the retryTable method because it will not be saved on the server. |
tableCallParams | TableCallParams? | An instance of the TableCallParams class describing query parameters. |
handler | HHFWCompletionHandler? | Callback function executed after query is completed. It is set to nil by default. |
Example:
let resourceName: String = "ResourceName"
let tableCallParams: TableCallParams = TableCallParams(defaultProperty: ())
HHFWController.sharedInstance().table(resourceName, transactionID: nil, tableCallParams: tableCallParams){ (jsonResult: Any?) in
// This block can be used to handle the jsonResult mobile platform server response in the json format
// jsonResult contains information about query, server response and query result
}
Asynchronous getting resource table data without loading to database (tableAsync)
The tableAsync method asynchronously requests resource table data without loading to database.
HHFWController.sharedInstance().tableAsync(_ resourceName: String?, transactionID: String?, tableCallParams: TableCallParams?, handler: HHFWCompletionHandler? = nil)
Input parameters:
Parameter | Data type | Description |
resourceName | String? | Name of resource. |
transactionID | String? | Transaction identifier. NOTE. If the parameter is set to nil, a transaction will be unavailable to get its repeated result using the retryTableAsync method because it will not be saved on the server. |
tableCallParams | TableCallParams? | An instance of the TableCallParams class describing query parameters. |
handler | HHFWCompletionHandler? | Callback function executed after query is completed. It is set to nil by default. |
Example:
let resourceName: String = "ResourceName"
let tableCallParams: TableCallParams = TableCallParams(defaultProperty: ())
HHFWController.sharedInstance().tableAsync(resourceName, transactionID: nil, tableCallParams: tableCallParams){ (jsonResult: Any?) in
// This block can be used to handle the jsonResult mobile platform server response in the json format
// jsonResult contains information about query, server response and query result
}
Synchronous request to resource without loading to database (request)
The request method synchronously sends an uniform request to resource without loading to database.
HHFWController.sharedInstance().request(_ resourceName: String, requestCallParams: RequestCallParams?, handler: HHFWCompletionHandler? = nil)
Input parameters:
Parameter | Data type | Description |
resourceName | String | Name of resource. |
requestCallParams | RequestCallParams? | An instance of the RequestCallParams class describing query parameters. |
handler | HHFWCompletionHandler? | Callback function executed after query is completed. It is set to nil by default. |
The method use is relevant when working with WEB resources where a mobile platform server is used as a proxy.
Example:
let resourceName: String = "ResourceName"
let requestCallParams: RequestCallParams = RequestCallParams(defaultProperty: ())
HHFWController.sharedInstance().request(resourceName, requestCallParams: requestCallParams){ (jsonResult: Any?) in
// This block can be used to handle the jsonResult mobile platform server response in the json format
// jsonResult contains information about query, server response and query result
}
Asynchronous request to resource without loading to database (requestAsync)
The requestAsync method asynchronously sends an uniform request to resource without loading to database.
HHFWController.sharedInstance().requestAsync(_ resourceName: String?, requestCallParams: RequestCallParams?, handler: HHFWCompletionHandler? = nil)
Input parameters:
Parameter | Data type | Description |
resourceName | String? | Name of resource. |
requestCallParams | RequestCallParams? | An instance of the RequestCallParams class describing query parameters. |
handler | HHFWCompletionHandler? | Callback function executed after query is completed. It is set to nil by default. |
The method use is relevant when working with WEB resources where a mobile platform server is used as a proxy.
Example:
let resourceName: String = "ResourceName"
let requestCallParams: RequestCallParams = RequestCallParams(defaultProperty: ())
HHFWController.sharedInstance().requestAsync(resourceName, requestCallParams: requestCallParams){ (jsonResult: Any?) in
// This block can be used to handle the jsonResult mobile platform server response in the json format
// jsonResult contains information about query, server response and query result
}
Set the path to the folder with files of the current resource downloading state (setDownloadPath)
The setDownloadPath method sets the path to the folder in the mobile application directory, which will store files of the current resource downloading state.
HHFWController.sharedInstance().setDownloadPath(_ path: String)
Input parameter:
Parameter | Data type | Description |
path | String | The path to the folder relative to the root directory of the mobile device file system where files of the current resource downloading state will be saved. If the specified folder does not exist, it is automatically created at the specified path. If the folder cannot be created, the files of the current resource downloading state are stored in the Documents folder. |
Example:
let path = downloadFileURL.path
HHFWController.sharedInstance().setDownloadPath(path)
Resume resource downloading (useDownload)
The useDownload method determines whether resource downloading is resumed.
HHFWController.sharedInstance().useDownload(_ val: Bool)
Input parameter:
Parameter | Data type | Description |
val | Bool | Determine resuming of resource downloading. Available values:
|
The method is used on failed attempt to download resource to resume resource downloading with saving the state at the moment of interruption. If resource downloading has failed or mobile platform server connection is lost, the mobile application keeps requesting resource.
To resume resource downloading, use the retryCount and retryIntervalSec properties of the auxiliary classes: RequestCallParams, TableCallParams, DeltaStreamCallParams on executing methods for working with the resources: deltaStream, deltaStreamAsync, tableStream, tableStreamAsync, table, tableAsync, request, requestAsync.
Order of using resuming of resource downloading:
Specify the path to the folder with file of the current resource downloading state by means of the setDownloadPath method after initializing iOS framework in the mobile application directory.
Enable resuming of resource downloading. To enable resuming of resource downloading, use the useDownload method with the True value.
Execute necessary methods for working with resources.
Disable resuming of resource downloading. To disable resuming of resource downloading, use the useDownload method with the False value.
Example:
let path = self.getURL(forFolder: "DownloadPath").path
HHFWController.sharedInstance().setDownloadPath(path)
HHFWController.sharedInstance().useDownload(true)
let requestCallParams: RequestCallParams = RequestCallParams(defaultDb: ())
requestCallParams?.dataBasePath = fullDatabaseURL.path
requestCallParams?.retryCount = 10
requestCallParams?.retryIntervalSec = 1
let resourceName: String = "ResourceName" // resource name
let isCached: Bool = true
HHFWController.sharedInstance().tableStream(resourceName, withCache: isCached, transactionID: nil, tableCallParams: requestCallParams){ (jsonResult: Any?) in
// This block can be used to handle the jsonResult mobile platform server response in the json format
// jsonResult contains information about query, server response and query result
}
The use of methods is given in the Examples of Working with Resources section.
To work with push notifications, use a mobile device, prepare the application to get push notifications and determine a device token.
To send push notifications from a mobile platform server to a mobile device, generate Apple Push Services certificate based on the certificates obtained in Apple Developer Account:
Download the required certificate from the developer account and add it to Keychain Access.
Open the certificate in Keychain Access.
Select the certificate and the closed key, export them to the required location with the *.p12 extension.
In the terminal go to the directory with exported file and convert it into the file with the *.pem extension.
cd Desktop // directory that contains exported file, for example, in the desktop
openssl pkcs12 -in pushcert.p12 -out pushcert.pem -nodes -clcerts
Add the certificate in the Apple Push Notification Service section when setting up push notifications.
For details about queries to send push notifications see the Method of Working with Push Notifications section.
Get list of active tokens (getTokens)
The getTokens method returns the list of tokens linked to the user at the server.
HHFWController.sharedInstance().getTokens(_ handler: HHFWCompletionHandler? = nil)
Input parameters:
Parameter | Data type | Description |
handler | HHFWCompletionHandler? | Callback function executed after query is completed. It is set to nil by default. |
Example:
HHFWController.sharedInstance().getTokens() { (jsonResult: Any?) in
// This block can be used to process response from jsonResult mobile platform server that is presented as JSON
// jsonResult contains information about query, server response and query result
}
Send token to server (addToken)
The addToken method sends token to server.
HHFWController.sharedInstance().addToken(_ token: String, service: String, completionHandler handler: HHFWCompletionHandler? = nil)
Input parameters:
Parameter | Data type | Description |
token | String | Device token. |
service | String | Name of push notifications service. |
completionHandler, handler | HHFWCompletionHandler? | Callback function executed after query is completed. It is set to nil by default. |
Example:
let token: String = "DeviceToken" // get during registration for remote notifications
let service: String = "apns"
HHFWController.sharedInstance().addToken(token, service: service) { (jsonResult: Any?) in
// This block can be used to process response from jsonResult mobile platform server that is presented as JSON
// jsonResult contains information about query, server response and query result
}
Remove tokens from server (removeTokens)
The removeTokens method removes sent tokens from server.
Several tokens can be removed at once by sending an array to the method.
HHFWController.sharedInstance().removeTokens(_ tokens: NSMutableArray, completionHandler handler: HHFWCompletionHandler? = nil)
Input parameters:
Parameter | Data type | Description |
tokens | NSMutableArray | Device tokens array. |
completionHandler, handler | HHFWCompletionHandler? | Callback function executed after query is completed. It is set to nil by default. |
Example:
let tokens: [String] = [token1, token2, ...] // message topic names
HHFWController.sharedInstance().removeTokens(tokens) { (jsonResult: Any?) in
// This block can be used to process response from jsonResult mobile platform server that is presented as JSON
// jsonResult contains information about query, server response and query result
}
Get message topics list (getTopics)
The getTopics method returns message topics list.
HHFWController.sharedInstance().getTopics(_ handler: HHFWCompletionHandler? = nil)
Input parameters:
Parameter | Data type | Description |
handler | HHFWCompletionHandler? | Callback function executed after query is completed. It is set to nil by default. |
Example:
HHFWController.sharedInstance().getTopics { (jsonResult) in
// This block can be used to process response from jsonResult mobile platform server that is presented as JSON
// jsonResult contains information about query, server response and query result
}
Set path to certification authority certificate file (setCAPemFilePath)
The setCAPemFilePath method sets path to the certification authority certificate file with the *.pem extension in the application local directory.
HHFWController.sharedInstance().setCAPemFilePath(_ path: String)
Input parameters:
Parameter | Data type | Description |
path | String | The path to pem file with certificate. |
Example:
let path: String = "PemFilePath"
HHFWController.sharedInstance().setCAPemFilePath(path)
Subscribe to messages (subscribeTopics)
The subscribeTopics method subscribes to messages with the specified topic.
HHFWController.sharedInstance().subscribeTopics(_ topics: NSMutableArray, completionHandler handler: HHFWCompletionHandler? = nil)
Input parameters:
Parameter | Data type | Description |
topics | NSMutableArray | Message topic names array. |
completionHandler, handler | HHFWCompletionHandler? | Callback function executed after query is completed. It is set to nil by default. |
Example:
let topics: [String] = [topic1, topic2, ...] // message topic names
HHFWController.sharedInstance().subscribeTopics(topics) { (jsonResult) in
// This block can be used to process response from jsonResult mobile platform server that is presented as JSON
// jsonResult contains information about query, server response and query result
}
Unsubscribe from messages (unsubscribeTopics)
The unsubscribeTopics method unsubscribes from messages with the specified topic.
HHFWController.sharedInstance().unsubscribeTopics(_ topics: NSMutableArray, completionHandler handler: HHFWCompletionHandler? = nil)
Input parameters:
Parameter | Data type | Description |
topics | NSMutableArray | Message topic names array. |
completionHandler, handler | HHFWCompletionHandler? | Callback function executed after query is completed. It is set to nil by default. |
Example:
let topics: [String] = [topic1, topic2, ...] // message topic names
HHFWController.sharedInstance().unsubscribeTopics(topics) { (jsonResult) in
// This block can be used to process response from jsonResult mobile platform server that is presented as JSON
// jsonResult contains information about query, server response and query result
}
The use of methods is given in the Example of Working with Push Notifications section.
Before executing the methods set up connection to folder on file server and add a permission to load data in the Info.plist in the mobile application project:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
Get information about directory contents (getDirectory)
The getDirectory method returns information about directory contents.
HHFWController.sharedInstance().getDirectory(_ directory: String, mountName: String, completionHandler handler: HHFWCompletionHandler? = nil)
Input parameters:
Parameter | Data type | Description |
directory | String | The path to the directory on server. |
mountName | String | Name of file server connection. |
completionHandler, handler | HHFWCompletionHandler? | Callback function executed after query is completed. It is set to nil by default. |
Example:
let directory: String = "DirectoryName"
let mountName: String = "MountName"
HHFWController.sharedInstance().getDirectory(directory, mountName: mountName) { (jsonResult) in
// This block can be used to process response from jsonResult mobile platform server that is presented as JSON
// jsonResult contains information about query, server response and query result
}
Get file information (getFileMeta)
The getFileMeta method returns file information.
HHFWController.sharedInstance().getFileMeta(_ filename: String, mountName: String, completionHandler handler: HHFWCompletionHandler? = nil)
Input parameters:
Parameter | Data type | Description |
filename | String | The path to the file on server. |
mountName | String | Name of file server connection. |
completionHandler, handler | HHFWCompletionHandler? | Callback function executed after query is completed. It is set to nil by default. |
Example:
let fileName: String = "FileName"
let mountName: String = "MountName"
HHFWController.sharedInstance().getFileMeta(fileName, mountName: mountName) { (jsonResult) in
// This block can be used to process response from jsonResult mobile platform server that is presented as JSON
// jsonResult contains information about query, server response and query result
}
Download file from server (getFile)
The getFile method downloads a file from a mobile platform server.
HHFWController.sharedInstance().getFile(_ filename: String, fromServerPath serverFileName: String, mountName: String, password: String, completionHandler handler: HHFWCompletionHandler? = nil)
Input parameters:
Parameter | Data type | Description |
filename | String | The path to the file in the mobile application directory relative to the Documents folder. |
fromServerPath, serverFileName | String | The path to the file on a mobile platform server. |
mountName | String | Name of file server connection. |
password | String | File encryption key on mobile device. When the non-empty key is specified, the downloaded file is encrypted on mobile device using this key. |
completionHandler, handler | HHFWCompletionHandler? | Callback function executed after query is completed. It is set to nil by default. |
Example:
let fileName: String = "FileName" // path to the file in the mobile platform directory
let serverFileName: String = "ServerFileName" // path to the file on a mobile platform server
let mountName: String = "MountName" // file server connection name
let fileKey: String = "FileKey" // file encryption key
HHFWController.sharedInstance().getFile(fileName, fromServerPath: serverFileName, mountName: mountName, password: fileKey) { (jsonResult) in
// This block can be used to handle the jsonResult mobile platform server response in the json format
// jsonResult contains information about request, mobile platform server response and request result
}
Upload file to server (putFile)
The putFile method uploads file to a mobile platform server.
HHFWController.sharedInstance().putFile(_ filename: String, toServerPath serverFileName: String, mountName: String, password: String, completionHandler handler: HHFWCompletionHandler? = nil)
Input parameters:
Parameter | Data type | Description |
filename | String | The path to the file in the mobile application directory relative to the Documents folder. |
toServerPath, serverFileName | String | The path to the file on a mobile platform server. |
mountName | String | Name of file server connection. |
password | String | File decryption key on mobile device. When a non-empty key is specified, the file is decrypted using this key and is uploaded to a mobile platform server. |
completionHandler, handler | HHFWCompletionHandler? | Callback function executed after query is completed. It is set to nil by default. |
Example:
let fileName: String = "FileName" // path to the file in the mobile platform directory
let serverFileName: String = "ServerFileName" // path to the file on a mobile platform server
let mountName: String = "MountName" // file server connection name
let fileKey: String = "FileKey" // file decryption key
HHFWController.sharedInstance().putFile(fileName, toServerPath: serverFileName, mountName: mountName, password: fileKey) { (jsonResult) in
// This block can be used to handle the jsonResult mobile platform server response in the json format
// jsonResult contains information about request, mobile platform server response and request result
}
Delete file from server (deleteFile)
The deleteFile method deletes file from a mobile platform server.
HHFWController.sharedInstance().deleteFile(_ filename: String, mountName: String, completionHandler handler: HHFWCompletionHandler? = nil)
Input parameters:
Parameter | Data type | Description |
filename | String | The path to the file on server. |
mountName | String | Name of file server connection. |
completionHandler, handler | HHFWCompletionHandler? | Callback function executed after query is completed. It is set to nil by default. |
Example:
let fileName: String = "FileName"
let mountName: String = "MountName"
HHFWController.sharedInstance().deleteFile(fileName, mountName: mountName) { (jsonResult) in
// This block can be used to process response from jsonResult mobile platform server that is presented as JSON
// jsonResult contains information about query, server response and query result
}
Check encryption key (checkPassword)
The checkPassword method checks validity of the encryption key specified in method parameters.
HHFWController.sharedInstance().checkPassword(_ filename: String, password: String) -> Bool
Input parameters:
Parameter | Data type | Description |
filename | String | The path to source file. |
password | String | File encryption key. |
The method returns True if valid encryption key is used, otherwise it returns False.
Example:
let fileName: String! = "FileName"
let fileKey: String! = "FileKey"
let passwordIsValid = HHFWController.sharedInstance().checkPassword(fileName, password: fileKey)
Decrypt file to a new file (decryptFile)
The decryptFile method decrypts the file and places decrypted contents to a new file.
HHFWController.sharedInstance().decryptFile(_ filename: String, toFile decryptedFilename: String, withPassword password: String)
Input parameters:
Parameter | Data type | Description |
filename | String | The path to the file, to which decrypted file contents is to be loaded. |
toFile, decryptedFilename | String | The path to the file to be decrypted. |
withPassword, password |
String | File encryption key on mobile device. |
Example:
let fileName: String = "FileName"
let fileKey: String = "FileKey"
let decryptedFilename: String = "DecryptedFilename"
HHFWController.sharedInstance().decryptFile(fileName, toFile: decryptedFilename, withPassword: fileKey)
Decrypt file to string (decryptFileToString)
The decryptFileToString method decrypts the file and places decrypted contents to a string.
HHFWController.sharedInstance().decryptFileToString(_ filename: String, withPassword password: String) -> String
Input parameters:
Parameter | Data type | Description |
filename | String | The path to the file to be decrypted in the mobile application directory relative to the Documents folder. |
withPassword, password |
String | File encryption key on mobile device. |
Example:
let fileName: String = "FileName"
let fileKey: String = "FileKey"
let decryptString: String = HHFWController.sharedInstance().decryptFileToString(fileName, withPassword: fileKey)
Decrypt file to byte buffer (decryptFileToData)
The decryptFileToData method decrypts the file and places decrypted contents to byte buffer.
HHFWController.sharedInstance().decryptFileToData(_ filename: String, withPassword password: String) -> Data
Input parameters:
Parameter | Data type | Description |
filename | String | The path to the file to be decrypted in the mobile application directory relative to the Documents folder. |
withPassword, password |
String | File encryption key on mobile device. |
Example:
let fileName: String = "FileName"
let fileKey: String = "FileKey"
let decryptData: Data = HHFWController.sharedInstance().decryptFileToData(fileName, withPassword: password)
Decrypt string to file (decryptString)
The decryptString method decrypts string to file in the application local directory.
HHFWController.sharedInstance().decryptString(_ string: String, toFile decryptedFilename: String, withPassword password: String) -> Bool
Input parameters:
Parameter | Data type | Description |
string | String | The string to be decrypted. |
toFile, decryptedFilename | String | The path to the decrypted file. |
withPassword, password | String | String encryption key on mobile device. |
The method returns True if the operation is successfully executed, otherwise it returns False.
Example:
let encryptedString: String = "EncryptedString"
let fileName: String = "Filename.txt"
let password: String = "Password"
let success = HHFWController.sharedInstance().decryptString(string, toFile: fileName, withPassword: password)
Decrypt string to new string (decryptStringToString)
The decryptStringToString method decrypts string to a new string.
HHFWController.sharedInstance().decryptStringToString(_ string: String, withPassword password: String) -> String
Input parameters:
Parameter | Data type | Description |
string | String | The string to be decrypted. |
withPassword, password | String | String encryption key on mobile device. |
Example:
let encryptedString: String = "EncryptedString"
let password: String = "Password"
let decryptedString = HHFWController.sharedInstance().decryptStringToString(encryptedString, withPassword: password)
Local byte buffer encryption to file (encryptData)
The encryptData method encrypts byte buffer to file in the application local directory.
HHFWController.sharedInstance().encryptData(_ data: Data, toFile filename: String, withPassword password: String) -> Bool
Input parameters:
Parameter | Data type | Description |
data | Data | The byte buffer to be decrypted. |
toFile, filename | String | The path to the file with encrypted byte buffer. |
withPassword, password | String | File encryption key. |
The method returns True if the operation is successfully executed, otherwise it returns False.
Example:
let data: Data = Data()
let encryptedFileName: String = "EncryptedFileName"
let fileKey: String = "FileKey"
let encryptionSuccess = HHFWController.sharedInstance().encryptData(data, toFile filename: encryptedFileName, withPassword password: fileKey)
Local file encryption to new file (encryptFile)
The encryptFile method encrypts file to a new file in the application local directory.
HHFWController.sharedInstance().encryptFile(_ filename: String, toFile encryptedFilename: String, withPassword password: String) -> Bool
Input parameters:
Parameter | Data type | Description |
filename | String | The path to source file. |
toFile, encryptedFilename | String | The path to the encrypted file. |
withPassword, password | String | File encryption key. |
The method returns True if the operation is successfully executed, otherwise it returns False.
Example:
let fileName: String = "FileName"
let encryptedFileName: String = "EncryptedFileName"
let fileKey: String = "FileKey"
let encryptionSuccess = HHFWController.sharedInstance().encryptFile(fileName, toFile: encryptedFileName, withPassword: fileKey)
Local file encryption to string (encryptFileToString)
The encryptFileToString method encrypts file to a string in the application local directory.
HHFWController.sharedInstance().encryptFileToString(_ filename: String, withPassword password: String) -> String
Input parameters:
Parameter | Data type | Description |
filename | String | Path to file. |
withPassword, password | String | File encryption key on mobile device. |
Example:
let fileName: String = "Filename.txt"
let password: String = "Password"
let encryptedString = HHFWController.sharedInstance().encryptFileToString(fileName, withPassword: password)
Local string encryption to file (encryptString)
The encryptString method encrypts string to a file in the application local directory.
HHFWController.sharedInstance().encryptString(_ string: String, toFile filename: String, withPassword password: String) -> Bool
Input parameters:
Parameter | Data type | Description |
string | String | The string to be encrypted. |
toFile, filename | String | The path to the file with the encrypted string. |
withPassword, password | String | File encryption key. |
The method returns True if the operation is successfully executed, otherwise it returns False.
Example:
let string: String = "String"
let encryptedFileName: String = "EncryptedFileName"
let fileKey: String = "FileKey"
let encryptionSuccess = HHFWController.sharedInstance().encryptString(string, toFile filename: encryptedFileName, withPassword password: fileKey)
Local string encryption to a new string (encryptStringToString)
The encryptStringToString method encrypts string to a new string.
HHFWController.sharedInstance().encryptStringToString(_ string: String, withPassword password: String) -> String
Input parameters:
Parameter | Data type | Description |
string | String | The string to be encrypted. |
withPassword, password | String | String encryption key on mobile device. |
Example:
let string: String = "Example"
let password: String = "Password"
let encryptedString = HHFWController.sharedInstance().encryptStringToString("Example", withPassword: password)
The use of methods is given in the Example of Working with File Encryption section.
For details about sending transaction data see the Sending Transaction Data section.
Get all transactions list (getAllTransactions)
The getAllTransactions method returns the list of all transactions.
HHFWController.sharedInstance().getAllTransactions(_ resourceName: String, completionHandler handler: HHFWCompletionHandler? = nil)
Input parameters:
Parameter | Data type | Description |
resourceName | String | Name of resource. |
completionHandler, handler | HHFWCompletionHandler? | Callback function executed after query is completed. It is set to nil by default. |
Example:
let resourceName: String = "ResourceName"
HHFWController.sharedInstance().getAllTransactions(resourceName, completionHandler: { (jsonResult: Any?) in
// This block can be used to handle the jsonResult mobile platform server response in the json format
// jsonResult contains information about query, server response and query result
}
Get response by transaction ID (getTransaction)
The getTransaction method returns the response from a mobile platform server by transaction ID.
HHFWController.sharedInstance().getTransaction(_ transactionID: String, resourceName name: String, completionHandler handler: HHFWCompletionHandler? = nil)
Input parameters:
Parameter | Data type | Description |
transactionID | String | Transaction identifier. |
resourceName, name | String | Name of resource. |
completionHandler, handler | HHFWCompletionHandler? | Callback function executed after query is completed. It is set to nil by default. |
Example:
let transactionID: String = UUID().uuidString
let tableCallParams: TableCallParams = TableCallParams(defaultProperty: ())
HHFWController.sharedInstance().table(resourceName, transactionID: transactionID, tableCallParams: tableCallParams, handler: {(jsonResult) in
// Get response to query by transactionID
HHFWController.sharedInstance().getTransaction(transactionID, resourceName: resourceName, completionHandler: { (jsonResult: Any?) in
// This block can process response from mobile platform server jsonResult that is presented JSON
// jsonResult contains information about query, server response, and query result
})
})
Repeated query with specifying transaction ID to get table data (retryTable)
The retryTable method executes repeated query to a mobile platform server to get saved data marked with transaction ID.
NOTE. The method is used after getting resource table data without loading to database.
HHFWController.sharedInstance().retryTable(_ resourceName: String, transactionID: String?, tableCallParams: TableCallParams?, handler: HHFWCompletionHandler? = nil)
Input parameters:
Parameter | Data type | Description |
resourceName | String | Name of resource. |
transactionID | String? | Transaction identifier. |
tableCallParams | TableCallParams? | An instance of the TableCallParams class describing query parameters. |
completionHandler, handler | HHFWCompletionHandler? | Callback function executed after query is completed. It is set to nil by default. |
Example:
let resourceName: String = "ResourceName"
let tableCallParams: TableCallParams = TableCallParams(defaultProperty: ())
HHFWController.sharedInstance().retryTable(resourceName, transactionID: transactionID, tableCallParams: tableCallParams){ (jsonResult: Any?) in
// This block can be used to handle the jsonResult mobile platform server response in the json format
// jsonResult contains information about query, server response and query result
}
Repeated query with specifying transaction ID for asynchronous getting table data without loading to database (retryTableAsync)
The retryTableAsync method executes repeated query to mobile platform server for asynchronous getting table data by transaction ID without loading to database.
NOTE. The method is used after asynchronous query of resource table data without loading to database.
HHFWController.sharedInstance().retryTableAsync(_ resourceName: String?, transactionID: String?, tableCallParams: TableCallParams?, handler: HHFWCompletionHandler? = nil)
Input parameters:
Parameter | Data type | Description |
resourceName | String | Name of resource. |
transactionID | String? | Transaction identifier. |
tableCallParams | RequestCallParams? | An instance of the RequestCallParams class describing query parameters. |
handler | HHFWCompletionHandler? | Callback function executed after query is completed. It is set to nil by default. |
Example:
let resourceName: String = "ResourceName"
let transactionID: String = "1234-5678-9012-3456-7890"
let requestCallParams: RequestCallParams = RequestCallParams(defaultDb: ())
requestCallParams?.dataBasePath = fullDatabaseURL.path
HHFWController.sharedInstance().retryTableAsync(resourceName, transactionID: transactionID, tableCallParams: requestCallParams){ (jsonResult: Any?) in
// This block can be used to handle the jsonResult mobile platform server response in the json format
// jsonResult contains information about query, server response and query result
}
Repeated query with specifying transaction ID for synchronous loading of table data to database (retryTableStream)
The retryTableStream method executes repeated query to mobile platform server for synchronous loading of table data by transaction ID to database.
NOTE. The method is used after synchronous loading of resource table data to database.
HHFWController.sharedInstance().retryTableStream(_ resourceName: String, withCache: Bool, transactionID: String?, tableCallParams: RequestCallParams?, handler: HHFWCompletionHandler? = nil)
Input parameters:
Parameter | Data type | Description |
resourceName | String | Name of resource. |
withCache | Bool | Indicates whether table caching is used in a local database. |
transactionID | String? | Transaction identifier. |
tableCallParams | RequestCallParams? | An instance of the RequestCallParams class describing query parameters. |
handler | HHFWCompletionHandler? | Callback function executed after query is completed. It is set to nil by default. |
Example:
let resourceName: String = "ResourceName"
let isCached: Bool = true
let transactionID: String = "1234-5678-9012-3456-7890"
let requestCallParams: RequestCallParams = RequestCallParams(defaultDb: ())
requestCallParams?.dataBasePath = fullDatabaseURL.path
HHFWController.sharedInstance().retryTableStream(resourceName, withCache: isCached, transactionID: transactionID, tableCallParams: requestCallParams){ (jsonResult: Any?) in
// This block can be used to handle the jsonResult mobile platform server response in the json format
// jsonResult contains information about query, server response and query result
}
Repeated query with specifying transaction ID for asynchronous loading of table data to database (retryTableStreamAsync)
The retryTableStreamAsync method executes repeated query to mobile platform server for asynchronous loading to table data by transaction ID to database.
NOTE. The method is used after asynchronous loading of resource table data to database.
HHFWController.sharedInstance().retryTableStreamAsync(_ resourceName: String?, withCache: Bool, transactionID: String?, tableCallParams: RequestCallParams?, handler: HHFWCompletionHandler? = nil)
Input parameters:
Parameter | Data type | Description |
resourceName | String? | Name of resource. |
withCache | Bool | Indicates whether table caching is used in a local database. |
transactionID | String? | Transaction identifier. |
tableCallParams | RequestCallParams? | An instance of the RequestCallParams class describing query parameters. |
handler | HHFWCompletionHandler? | Callback function executed after query is completed. It is set to nil by default. |
Example:
let resourceName: String = "ResourceName"
let isCached: Bool = true
let transactionID: String = "1234-5678-9012-3456-7890"
let requestCallParams: RequestCallParams = RequestCallParams(defaultDb: ())
requestCallParams?.dataBasePath = fullDatabaseURL.path
HHFWController.sharedInstance().retryTableStreamAsync(resourceName, withCache: isCached, transactionID: transactionID, tableCallParams: requestCallParams){ (jsonResult: Any?) in
// This block can be used to handle the jsonResult mobile platform server response in the json format
// jsonResult contains information about query, server response and query result
}
Delete transaction information (deleteTransaction)
The deleteTransaction method deletes transaction information.
HHFWController.sharedInstance().deleteTransaction(_ transactionID: String, resourceName name: String, completionHandler handler: HHFWCompletionHandler? = nil)
Input parameters:
Parameter | Data type | Description |
transactionID | String | Transaction identifier. |
resourceName, name | String | Name of resource. |
completionHandler, handler | HHFWCompletionHandler? | Callback function executed after query is completed. It is set to nil by default. |
Example:
let transactionID: String = "c4f64acd-7e0f-4bd7-ba32-9a15271f3eb4"
HHFWController.sharedInstance().deleteTransaction(transactionID, resourceName: resourceName, completionHandler: { (jsonResult: Any?) in
// This block can be used to process response from jsonResult mobile platform server that is presented as JSON
// jsonResult contains information about query, server response and query result
})
The use of methods is given in the Example of Working with Transactions section.
Before executing the methods set up parameters of connection to DSS CryptoPro.
Get certificates list (getCertificatesWithPassword)
The getCertificatesWithPassword method returns certificates list.
HHFWController.sharedInstance().getCertificatesWithPassword(_ password: String, completionHandler handler: HHFWCompletionHandler? = nil)
Input parameters:
Parameter | Data type | Description |
password | String | DSS user password. |
completionHandler, handler | HHFWCompletionHandler? | Callback function executed after query is completed. It is set to nil by default. |
Example:
let dssPassword: String = "DSSPassword"
HHFWController.sharedInstance().getCertificatesWithPassword(dssPassword) { (jsonResult) in
// This block can be used to process response from jsonResult mobile platform server that is presented as JSON
// jsonResult contains information about query, server response and query result
}
Get digital signatures history (signs)
The signs method returns the list of digital signatures that were created by the current user.
HHFWController.sharedInstance().signs(completionHandler handler: HHFWCompletionHandler? = nil)
Input parameters:
Parameter | Data type | Description |
completionHandler, handler | HHFWCompletionHandler? | Callback function executed after query is completed. It is set to nil by default. |
Example:
HHFWController.sharedInstance().signs { (jsonResult) in
// This block can be used to process response from jsonResult mobile platform server that is presented as JSON
// jsonResult contains information about query, server response and query result
}
Send document to sign (signCertificate)
The signCertificate method sends a document to sign.
HHFWController.sharedInstance().signCertificate(withResource resource: String, table: String, params requestParams: String, column: String, hhiveId: String, password: String, certificateId: String, certificatePin: String, completionHandler handler: HHFWCompletionHandler? = nil)
Input parameters:
Parameter | Data type | Description |
withResource, resource | String | Name of resource. |
table | String | Table name. |
params, requestParams | String | JSON string with parameters, with which query was executed. |
column | String | Table column name. |
hhiveId | String | Table row name. |
password | String | DSS password. |
certificateId | String | Certificate identifier. |
certificatePin | String | Certificate PIN. |
completionHandler, handler | HHFWCompletionHandler? | Callback function executed after query is completed. It is set to nil by default. |
Example:
let resourceName: String = "ResourceName"
let tableName: String = "TableName"
let params: String = "{key1: value1, key2: value2, ...}"
let column: String = "ColumnName"
let hhiveId: String = "HhiveId"
let dssPassword: String = "DSSPassword"
let certificateId: String = "CertificateId"
let certificatePin: String = "CertificatePin"
HHFWController.sharedInstance().signCertificate(
withResource: resourceName,
table: tableName,
params: params,
column: column,
hhiveId: hhiveId,
password: dssPassword,
certificateId: certificateId,
certificatePin: certificatePin
) { (jsonResult) in
// This block can be used to process response from jsonResult mobile platform server that is presented as JSON
// jsonResult contains information about query, server response and query result
}
After executing the method the document is signed, and a mobile platform server returns signature identifier as {"signature_id": 35}.
Remove digital signature (remove)
The remove method removes digital signature.
HHFWController.sharedInstance().remove(withSignId signId: Int, completionHandler handler: HHFWCompletionHandler? = nil)
Input parameters:
Parameter | Data type | Description |
withSignId, signId | Int | Signature identifier. |
completionHandler, handler | HHFWCompletionHandler? | Callback function executed after query is completed. It is set to nil by default. |
Example:
let signatureID: Int = 1
HHFWController.sharedInstance().remove(withSignId: signatureId) { (jsonResult) in
// This block can be used to process response from jsonResult mobile platform server that is presented as JSON
// jsonResult contains information about query, server response and query result
}
The use of methods is given in the Example of Working with Digital Signature section.
Access to WEB resources is made as via proxy. A mobile platform server is used as a mediator between a mobile device and WEB resources.
Before executing the method make sure that the connection is opened with local database, and resources schemes are loaded.
Universal WEB resource request (webRequest)
The webRequest method sends universal request to WEB resource.
HHFWController.sharedInstance().webRequest(_ type: WebRequestType, resourceName: String, requestCallParams: RequestCallParams, completionHandler handler: HHFWCompletionHandler? = nil)
Input parameters:
Parameter | Data type | Description |
type | WebRequestType | Used HTTP method:
|
resourceName | String | Name of resource. |
requestCallParams | RequestCallParams | An instance of the RequestCallParams class describing query parameters. |
completionHandler, handler | HHFWCompletionHandler? | Callback function executed after query is completed. It is set to nil by default. |
Example:
let httpMethod: WebRequestType = .Post
let resourceName: String = "ResourceName"
let requestCallParams: RequestCallParams = RequestCallParams(defaultProperty: ())
HHFWController.sharedInstance().webRequest(httpMethod, resourceName: resourceName, requestCallParams: requestCallParams){ (jsonResult: Any?) in
// In this block one can process the jsonResult mobile platform server response in the JSON format
// jsonResult contains information about query, server response and query result
}
Use the POST HTTP method on request to WEB resource (webPost)
The webPost method sends request to WEB resource with the use of the POST HTTP method.
HHFWController.sharedInstance().webPost(_ resourceName: String, requestCallParams: RequestCallParams, completionHandler handler: HHFWCompletionHandler? = nil)
Input parameters:
Parameter | Data type | Description |
resourceName | String | Name of resource. |
requestCallParams | RequestCallParams | An instance of the RequestCallParams class describing query parameters. |
completionHandler, handler | HHFWCompletionHandler? | Callback function executed after query is completed. It is set to nil by default. |
Example:
let resourceName: String = "ResourceName"
let requestCallParams: RequestCallParams = RequestCallParams(defaultProperty: ())
HHFWController.sharedInstance().webPost(resourceName, requestCallParams: requestCallParams){ (jsonResult: Any?) in
// In this block one can process the jsonResult mobile platform server response in the JSON format
// jsonResult contains information about query, server response and query result
}
Use the GET HTTP method on request to WEB resource (webGet)
The webGet method sends request to WEB resource with the use of the GET HTTP method.
HHFWController.sharedInstance().webGet(_ resourceName: String, requestCallParams: RequestCallParams, completionHandler handler: HHFWCompletionHandler? = nil)
Input parameters:
Parameter | Data type | Description |
resourceName | String | Name of resource. |
requestCallParams | RequestCallParams | An instance of the RequestCallParams class describing query parameters. |
completionHandler, handler | HHFWCompletionHandler? | Callback function executed after query is completed. It is set to nil by default. |
Example:
let resourceName: String = "ResourceName"
let requestCallParams: RequestCallParams = RequestCallParams(defaultProperty: ())
HHFWController.sharedInstance().webGet(resourceName, requestCallParams: requestCallParams){ (jsonResult: Any?) in
// In this block one can process the jsonResult mobile platform server response in the JSON format
// jsonResult contains information about query, server response and query result
}
Use the TRACE HTTP method on request to WEB resource (webTrace)
The webTrace method sends request to WEB resource with the use of the TRACE HTTP method.
HHFWController.sharedInstance().webTrace(_ resourceName: String, requestCallParams: RequestCallParams, completionHandler handler: HHFWCompletionHandler? = nil)
Input parameters:
Parameter | Data type | Description |
resourceName | String | Name of resource. |
requestCallParams | RequestCallParams | An instance of the RequestCallParams class describing query parameters. |
completionHandler, handler | HHFWCompletionHandler? | Callback function executed after query is completed. It is set to nil by default. |
Example:
let resourceName: String = "ResourceName"
let requestCallParams: RequestCallParams = RequestCallParams(defaultProperty: ())
HHFWController.sharedInstance().webTrace(resourceName, requestCallParams: requestCallParams){ (jsonResult: Any?) in
// In this block one can process the jsonResult mobile platform server response in the JSON format
// jsonResult contains information about query, server response and query result
}
Use the HEAD HTTP method on request to WEB resource (webHead)
The webHead method sends request to WEB resource with the use of the HEAD HTTP method.
HHFWController.sharedInstance().webHead(_ resourceName: String, requestCallParams: RequestCallParams, completionHandler handler: HHFWCompletionHandler? = nil)
Input parameters:
Parameter | Data type | Description |
resourceName | String | Name of resource. |
requestCallParams | RequestCallParams | An instance of the RequestCallParams class describing query parameters. |
completionHandler, handler | HHFWCompletionHandler? | Callback function executed after query is completed. It is set to nil by default. |
Example:
let resourceName: String = "ResourceName"
let requestCallParams: RequestCallParams = RequestCallParams(defaultProperty: ())
HHFWController.sharedInstance().webHead(resourceName, requestCallParams: requestCallParams){ (jsonResult: Any?) in
// In this block one can process the jsonResult mobile platform server response in the JSON format
// jsonResult contains information about query, server response and query result
}
Use the PUT HTTP method on request to WEB resource (webPut)
The webPut method sends request to WEB resource with the use of the PUT HTTP method.
HHFWController.sharedInstance().webPut(_ resourceName: String, requestCallParams: RequestCallParams, completionHandler handler: HHFWCompletionHandler? = nil)
Input parameters:
Parameter | Data type | Description |
resourceName | String | Name of resource. |
requestCallParams | RequestCallParams | An instance of the RequestCallParams class describing query parameters. |
completionHandler, handler | HHFWCompletionHandler? | Callback function executed after query is completed. It is set to nil by default. |
Example:
let resourceName: String = "ResourceName"
let requestCallParams: RequestCallParams = RequestCallParams(defaultProperty: ())
HHFWController.sharedInstance().webPut(resourceName, requestCallParams: requestCallParams){ (jsonResult: Any?) in
// In this block one can process the jsonResult mobile platform server response in the JSON format
// jsonResult contains information about query, server response and query result
}
Use the DELETE HTTP method on request to WEB resource (webDelete)
The webDelete method sends request to WEB resource with the use of the DELETE HTTP method.
HHFWController.sharedInstance().webDelete(_ resourceName: String, requestCallParams: RequestCallParams, completionHandler handler: HHFWCompletionHandler? = nil)
Input parameters:
Parameter | Data type | Description |
resourceName | String | Name of resource. |
requestCallParams | RequestCallParams | An instance of the RequestCallParams class describing query parameters. |
completionHandler, handler | HHFWCompletionHandler? | Callback function executed after query is completed. It is set to nil by default. |
Example:
let resourceName: String = "ResourceName"
let requestCallParams: RequestCallParams = RequestCallParams(defaultProperty: ())
HHFWController.sharedInstance().webDelete(resourceName, requestCallParams: requestCallParams){ (jsonResult: Any?) in
// In this block one can process the jsonResult mobile platform server response in the JSON format
// jsonResult contains information about query, server response and query result
}
Use the PATCH HTTP method on request to WEB resource (webPatch)
The webPatch method sends request to WEB resource with the use of the PATCH HTTP method.
HHFWController.sharedInstance().webPatch(_ resourceName: String, requestCallParams: RequestCallParams, completionHandler handler: HHFWCompletionHandler? = nil)
Input parameters:
Parameter | Data type | Description |
resourceName | String | Name of resource. |
requestCallParams | RequestCallParams | An instance of the RequestCallParams class describing query parameters. |
completionHandler, handler | HHFWCompletionHandler? | Callback function executed after query is completed. It is set to nil by default. |
Example:
let resourceName: String = "ResourceName"
let requestCallParams: RequestCallParams = RequestCallParams(defaultProperty: ())
HHFWController.sharedInstance().webPatch(resourceName, requestCallParams: requestCallParams){ (jsonResult: Any?) in
// In this block one can process the jsonResult mobile platform server response in the JSON format
// jsonResult contains information about query, server response and query result
}
Use the OPTIONS HTTP method on request to WEB resource (webOptions)
The webOptions method sends request to WEB resource with the use of the OPTIONS HTTP method.
HHFWController.sharedInstance().webOptions(_ resourceName: String, requestCallParams: RequestCallParams, completionHandler handler: HHFWCompletionHandler? = nil)
Input parameters:
Parameter | Data type | Description |
resourceName | String | Name of resource. |
requestCallParams | RequestCallParams | An instance of the RequestCallParams class describing query parameters. |
completionHandler, handler | HHFWCompletionHandler? | Callback function executed after query is completed. It is set to nil by default. |
Example:
let resourceName: String = "ResourceName"
let requestCallParams: RequestCallParams = RequestCallParams(defaultProperty: ())
HHFWController.sharedInstance().webOptions(resourceName, requestCallParams: requestCallParams){ (jsonResult: Any?) in
// In this block one can process the jsonResult mobile platform server response in the JSON format
// jsonResult contains information about query, server response and query result
}
Accessing Foresight Analytics Platform is executed identically to accessing WEB resources.
Request to Foresight Analytics Platform (request)
The "request" method sends a request to Foresight Analytics Platform.
HHFWController.sharedInstance().request(_ resourceName: String, requestCallParams: RequestCallParams?, handler: HHFWCompletionHandler? = nil)
Input parameters:
Parameter | Data type | Description |
resourceName | String | Name of resource. |
requestCallParams | RequestCallParams? | An instance of the RequestCallParams class describing query parameters. |
handler | HHFWCompletionHandler? | Callback function executed after query is completed. It is set to nil by default. |
let resourceName: String = "FAPResourceName"
let requestCallParams: RequestCallParams = RequestCallParams(defaultProperty: ())
requestCallParams?.data = "{}"
HHFWController.sharedInstance().request(resourceName, requestCallParams: requestCallParams) { (jsonResult) in
// This block can be used to process response from jsonResult mobile platform server that is presented as JSON
// jsonResult contains information about query, server response and query result
}
The method use is given in the Example of Working with Foresight
The logFatal method writes an error to the log, after which the application can work but results may be unexpected. The error is displayed in the console.
NOTE. The logging level should take the 6 value to write error to the log.
HHFWController.sharedInstance().logFatal(_ msg: String?)
Input parameters:
Parameter | Data type | Description |
msg | String? | Error text. |
Example:
let message: String = "Error Message"
HHFWController.sharedInstance().logFatal(message)
Write message to log (logTrace)
The logTrace method writes a message with the following information to the log: statistics, key settings, start/stop status, and so on. The message is displayed in the console.
NOTE. The logging level should take the 4 value to write a message to the log.
HHFWController.sharedInstance().logTrace(_ msg: String?)
Input parameters:
Parameter | Data type | Description |
msg | String? | Message text. |
Example:
let message: String = "Trace Message"
HHFWController.sharedInstance().logTrace(message)
Write warning to log (logWarning)
The logWarning method writes the warning to the log informing the user or developer that they should pay attention to application work result. The warning is displayed in the console.
NOTE. The logging level should take the 5 value to write a warning to the log.
HHFWController.sharedInstance().logWarning(_ msg: String?)
Input parameters:
Parameter | Data type | Description |
msg | String? | Warning text. |
Example:
let message: String = "Warning Message"
HHFWController.sharedInstance().logWarning(message)
Set path to logs database (setLogDBPath)
The setLogDBPath method sets a path to the database, to which logs will be written.
HHFWController.sharedInstance().setLogDBPath(_ databasePath: String, password: String)
Input parameters:
Parameter | Data type | Description |
databasePath | String | The path to the database server relative to the root directory of the mobile device file system. NOTE. The database should differ from the database used for working with resources. |
password | String | Database encryption key. |
Example:
let databasePath: String = "DatabasePath"
let databaseKey: String = "DatabaseKey"
HHFWController.sharedInstance().setLogDBPath(databasePath, password: databaseKey)
Display framework log in the console (setLogEnabled)
The setLogEnabled method determines whether framework log is displayed in the console.
HHFWController.sharedInstance().setLogEnabled(_ enabled: Bool)
Input parameters:
Parameter | Data type | Description |
enabled | Bool | Determine whether framework log is displayed in the console. Available values:
|
Example:
let isDebugMode: Bool = true
HHFWController.sharedInstance().setLogEnabled(isDebugMode)
Set logging level (setLogLevel)
The setLogLevel method sets a logging level.
Logging level enables the user to manage the amount of information that is returned on executing framework methods and is displayed in the debug output box in the development environment. Managing information output facilitates the development.
For example, the first logging level displays JSON responses from a mobile platform server to data queries and SQL queries to local database. When the first logging level is changed for the third logging level, JSON responses are not displayed.
HHFWController.sharedInstance().setLogLevel(_ level: Int32)
Input parameters:
Parameter | Data type | Description |
level | Int32 | Logging level:
|
Example:
let logLevel: Int32 = 1
HHFWController.sharedInstance().setLogLevel(logLevel)
Send logs to mobile platform server (syncLogs)
The syncLogs method sends logs from a mobile device to mobile platform server.
HHFWController.sharedInstance().syncLogs(withClean: Bool, completionHandler handler: HHFWCompletionHandler? = nil)
Input parameters:
Parameter | Data type | Description |
withClean |
Bool | Indicates whether log records are cleared after mobile device logs synchronization on mobile platform server:
|
completionHandler, handler |
HHFWCompletionHandler? | Callback function executed after query is completed. It is set to nil by default. |
Example:
let withClean: Bool = true
HHFWController.sharedInstance().syncLogs(withClean: withClean) { (jsonResult: Any?) in
// This block can be used to handle the jsonResult mobile platform server response in the json format
// jsonResult contains information about query, server response and query result
}
Get logs synchronization schedule (syncLogsSchedule)
The syncLogsSchedule method requests logs synchronization on mobile platform server.
HHFWController.sharedInstance().syncLogsSchedule(completionHandler handler: HHFWCompletionHandler? = nil)
Input parameters:
Parameter | Data type | Description |
completionHandler, handler |
HHFWCompletionHandler? | Callback function executed after query is completed. It is set to nil by default. |
Example:
HHFWController.sharedInstance().syncLogsSchedule() { (jsonResult: Any?) in
// This block can be used to handle the jsonResult mobile platform server response in the json format
// jsonResult contains information about query, server response and query result
}
The state method gets state of user credentials and resources scheme in the JSON format.
HHFWController.sharedInstance().state() -> String?
Example:
let state = HHFWController.sharedInstance().state()
The setState method sets state according to the specified value of input parameter.
HHFWController.sharedInstance().setState(_ state: String) -> Bool
Input parameters:
Parameter | Data type | Description |
state | String | State in the JSON format. NOTE. If the parameter is set to null, the current state will be reset. |
The method returns True if the operation is successfully executed, otherwise it returns False.
Example:
let state: String = "state"
HHFWController.sharedInstance().setState(state)
See. also:
HHFW Framework | Examples of iOS Framework Use