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 | The path to the database server relative to the root directory of the mobile device file system. |
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 = ""
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. 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.
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 server relative to the root directory of the mobile device file system. |
resourceName, resource | String | Resource name. |
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 caching is not used, tables are not found. To get table names, set resource name and table name as follows: <resourceName>_<tableName>, where:
resourceName. Resource name
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 server relative to the root directory of the mobile device file system. |
resourceName, resource | String | Resource name. |
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 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 | The path to the database server relative to the root directory of the mobile device file system. |
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, 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(_ 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
}
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:
NOTE. Resuming of resource downloading is disabled in the framework by default. |
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 RequestCallParams, TableCallParams, DeltaStreamCallParams auxiliary classes on executing methods for working with the deltaStream, deltaStreamAsync, tableStream, tableStreamAsync, table, tableAsync, request, requestAsync resources.
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
}
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)
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 | 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 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 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 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 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 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 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 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
}
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)
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 | 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
}
The methods use is given in the Example of Working with File Encryption article.
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)
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)
See also:
iOS Framework | Initializing iOS Framework | Examples of iOS Framework Use