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 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 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 mobile platform server.
Cancel authentication (unAuth)
The unAuth method cancels user authentication.
HHFWController.sharedInstance().unAuth()
The methods use is given in the Examples of Authentication on Mobile Platform Server examples.
Mobile platform server accessibility check (connectionStatus)
The connectionStatus method checks mobile platform server accessibility.
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 Accessibility Check example.
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 | Path to database file (on a mobile device). |
key | String | Database encryption key. |
handler | HHFWCompletionHandler? | Callback function executed after query is completed. It is set to nil by default. |
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 = ""
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 in the mobile application directory. |
newKey | String | New database encryption key. |
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? | Path to database file (in application folder) |
query | String | SQL query. |
Table name format in local database: <resourceName>_<hash>_<tableName>, where:
resourceName. Resource name.
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.
Example:
let jsonResult: String? = HHFWController.sharedInstance().query("/Documents/\(databaseName)", query: "SELECT * FROM TableNameInDatabase WHERE `key` = 'value'")
Get table name (getTablesName)
The getTablesName method returns the table name in local database.
HHFWController.sharedInstance().getTablesName(_ databasePath: String, resourceName resource: String, requestParams params: String, tableName table: String?) -> String?
Input parameters:
Parameter | Data type | Description |
databasePath | String | Path to database file (in application folder) |
resourceName, resource | String | Resource name. |
requestParams, params | String | JSON string with parameters, with which query was executed. |
tableName, table | String? | Table name at server. It is used to get a specific table in a multi-table resource. |
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 | Path to database file (in application folder) |
resourceName, resource | String | Resource name. |
requestParams, params | String | JSON string with parameters, with which query was executed. |
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 files with the *.sqlite extension from the DocumentDirectory application folder, use the query 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 | Path to database file (on a mobile device). |
The method can be used if authentication is canceled.
The use of methods is given in examples 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.
HHFWController.sharedInstance().resources(_ database: String?, handler: HHFWCompletionHandler? = nil)
Input parameters:
Parameter | Data type | Description |
database | String | Name of database in use. |
handler | HHFWCompletionHandler? | Callback function executed after query is completed. It is set to nil by default. |
Example:
let databaseName: String = "database.sqlite"
HHFWController.sharedInstance().resources(databaseName){ (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 scheme request, server response and resources scheme
}
After executing the method the resources scheme is automatically written to the specified database.
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(_ resourseName: String, deltaStreamCallParams: DeltaStreamCallParams?, handler: HHFWCompletionHandler? = nil)
Input parameters:
Parameter | Data type | Description |
resourseName | String | Resource name. |
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 initializing 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
HHFWController.sharedInstance().deltaStream(resourceName, deltaStreamCallParams: deltaStreamCallParams){ (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
}
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 |
resourseName | String | Resource name. |
withCache | Bool | The checkbox that determines whether tables are cached 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 initializing 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(_ resourseName: String, transactionID: String?, tableCallParams: RequestCallParams?, handler: HHFWCompletionHandler? = nil)
Input parameters:
Parameter | Data type | Description |
resourseName | String | Resource name. |
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. |
When initializing 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 requestCallParams: RequestCallParams = RequestCallParams(defaultDb: ())
requestCallParams?.dataBasePath = fullDatabaseURL.path
let resourceName: String = "ResourceName" // resource name
HHFWController.sharedInstance().tableStream(resourceName, transactionID: nil, tableCallParams: requestCallParams){ (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
}
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(_ resourseName: String, withCache: Bool, transactionID: String, tableCallParams: RequestCallParams?, handler: HHFWCompletionHandler? = nil)
Input parameters:
Parameter | Data type | Description |
resourseName | String | Resource name. |
withCache | Bool | The checkbox that determines whether tables are cached 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. |
When initializing 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 requestCallParams: RequestCallParams = RequestCallParams(defaultDb: ())
requestCallParams?.dataBasePath = fullDatabaseURL.path
let resourceName: String = "ResourceName" // resource name
HHFWController.sharedInstance().tableStreamAsync(resourceName, withCache: isCached, transactionID: nil, tableCallParams: requestCallParams){ (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 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(_ resourseName: String, transactionID: String?, tableCallParams: TableCallParams?, handler: HHFWCompletionHandler? = nil)
Input parameters:
Parameter | Data type | Description |
resourseName | String | Resource name. |
transactionID | String? | Transaction identifier. |
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 tableCallParams: TableCallParams = TableCallParams(defaultProperty: ())
HHFWController.sharedInstance().table(resourceName, transactionID: nil, tableCallParams: tableCallParams){ (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
}
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(_ resourseName: String, transactionID: String, tableCallParams: TableCallParams?, handler: HHFWCompletionHandler? = nil)
Input parameters:
Parameter | Data type | Description |
resourseName | String | Resource name. |
transactionID | String? | Transaction identifier. |
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 tableCallParams: TableCallParams = TableCallParams(defaultProperty: ())
HHFWController.sharedInstance().tableAsync(resourceName, transactionID: nil, tableCallParams: tableCallParams){ (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 information about query, server response and query result
}
Sychronous 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(_ resourseName: String, requestCallParams: RequestCallParams?, handler: HHFWCompletionHandler? = nil)
Input parameters:
Parameter | Data type | Description |
resourseName | String | Resource name. |
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 mobile platform server is used as a proxy.
Example:
let requestCallParams: RequestCallParams = RequestCallParams(defaultProperty: ())
HHFWController.sharedInstance().request(resourceName, requestCallParams: requestCallParams){ (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
}
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(_ resourseName: String, requestCallParams: RequestCallParams?, handler: HHFWCompletionHandler? = nil)
Input parameters:
Parameter | Data type | Description |
resourseName | String | Resource name. |
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 mobile platform server is used as a proxy.
Example:
let requestCallParams: RequestCallParams = RequestCallParams(defaultProperty: ())
HHFWController.sharedInstance().requestAsync(resourceName, requestCallParams: requestCallParams){ (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 information about query, server response and query result
}
The methods deltaStream, deltaStreamAsync, tableStream, tableStreamAsync, table, tableAsync, request, requestAsync have input parameters of one of the classes:
RequestCallParams.
TableCallParams.
DeltaStreamCallParams.
Input parameters contain the properties that are used to set up resuming resource downloading on unsuccessful downloading attempt.
Properties of input parameters:
Property | Data type | Description |
retryCount | Int | Number of resource downloading repetitions. |
retryIntervalSec | Int | Interval between repetitions, seconds. |
Example:
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 response of the jsonResult mobile platform server that is presented as json.
// jsonResult contains information about query, mobile platform server response, and query result.
}
The order of using the functionality for resuming resource downloading:
After initializing Sailfish framework in the mobile application directory specify path to the folder with download resumption files.
Enable resuming resource downloading
Execute resource requesting methods
Disable resuming resource downloading.
Set path to download resumption file (setFilePath)
The setFilePath method sets path to the folder in the mobile application directory, which will store download resumption files.
HHFWController.sharedInstance().setFilePath(_ path: String)
Input parameter:
Parameter | Data type | Description |
path | String | The path to the folder in the mobile application directory, which will store download resumption files. |
The path to the Documents folder is set by default.
Example:
let path = downloadFileURL.path
HHFWController.sharedInstance().setFilePath(path)
Enable and disable resuming resource downloading (useDownload)
The useDownload method enables or disables resuming resource downloading.
HHFWController.sharedInstance().useDownload(_ val: Bool)
Input parameter:
Parameter | Data type | Description |
val | Bool | The checkbox that determines whether resuming resource downloading is used. |
Resuming resource downloading is disabled by default. To enable resuming resource downloading, call the useDownload method and set the input parameter to True; to disable, set the input parameter to False.
Example:
let isUsingDownload: Bool = true
HHFWController.sharedInstance().useDownload(isUsingDownload)
The use of methods is given in examples 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 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
}
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 at file server and add a permissions 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 | Directory. |
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 | Path to file. |
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 mobile platform server.
HHFWController.sharedInstance().getFile(_ filename: String, mountName: String, completionHandler handler: HHFWCompletionHandler? = nil)
Input parameters:
Parameter | Data type | Description |
filename | String | Path to file. |
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
}
Upload file to server (putFile)
The putFile method uploads file to mobile platform server.
HHFWController.sharedInstance().putFile(_ filename: String, mountName: String, completionHandler handler: HHFWCompletionHandler? = nil)
Input parameters:
Parameter | Data type | Description |
filename | String | Path to file. |
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().putFile(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
}
Delete file from server (deleteFile)
The deleteFile method deletes file from mobile platform server.
HHFWController.sharedInstance().deleteFile(_ filename: String, mountName: String, completionHandler handler: HHFWCompletionHandler? = nil)
Input parameters:
Parameter | Data type | Description |
filename | String | Path to file. |
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
}
The use of methods is given in the Example of Working with Files section.
For details about sending transaction data see the Sending Transaction Data section.
Get all transactions list (getAllTransactionResourceName)
The getAllTransactionResourceName method returns all transactions list.
HHFWController.sharedInstance().getAllTransactionResourceName(_ name: String, completionHandler handler: HHFWCompletionHandler? = nil)
Input parameters:
Parameter | Data type | Description |
name | String | Resource name. |
completionHandler, handler | HHFWCompletionHandler? | Callback function executed after query is completed. It is set to nil by default. |
Example:
HHFWController.sharedInstance().getAllTransactionResourceName(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
}
Get response by transaction ID (getTransaction)
The getTransaction method returns the response from 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 | Resource name. |
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 (retryTable)
The retryTable method executes repeated query to 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(_ resuurceName: String, transactionID: String?, tableCallParams: TableCallParams?, handler: HHFWCompletionHandler? = nil)
Input parameters:
Parameter | Data type | Description |
resourceName, name | String | Resource name. |
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 tableCallParams: TableCallParams = TableCallParams(defaultProperty: ())
HHFWController.sharedInstance().retryTable(resourceName, transactionID: transactionID, tableCallParams: tableCallParams){ (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
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 | Resource name. |
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 | Resource name. |
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 the 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. The mobile platform server is used as an intermediary 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.
Request to WEB resources (request)
The request method sends a request to WEB resources.
HHFWController.sharedInstance().request(_ resourseName: String, requestCallParams: RequestCallParams?, handler: HHFWCompletionHandler? = nil)
Input parameters:
Parameter | Data type | Description |
resourseName | String | Resource name. |
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. |
If the used instance of the RequestCallParams class sets the "data" parameter (JSON string), a POST request is executedl if the string is empty, a GET request is executed.
Example:
let resourceName: String = "WebResourceName"
let requestCallParams: RequestCallParams = RequestCallParams(defaultProperty: ())
// For POST request
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 WEB Resources section.
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(_ resourseName: String, requestCallParams: RequestCallParams?, handler: HHFWCompletionHandler? = nil)
Input parameters:
Parameter | Data type | Description |
resourseName | String | Resource name. |
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. |
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 Analytics Platform. section.
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 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)
See also:
iOS Framework | Initializing iOS Framework | Examples of iOS Framework Use