kony.application.settings Namespace
The kony.application.settings Namespace provides the following API elements.
Functions
This function enables your app to read the configuration values associated with specified keys.
Syntax
kony.application.settings.read(key, onsuccesscallback, onfailureback);
Input Parameters
Parameters | Description |
---|---|
key | A string that specifies the keys for the settings to read. |
onsuccesscallback | A function that is executed when the key-value pair specified in the key parameter is read successfully. For details, see the Remarks section below. |
onfailurecallback | A callback function is executed when there is an error in fetching the app's settings. This callback function receives the error code and the error message. For details, see the Remarks section below. |
Example
read: function() { kony.application.settings.read("key1", this.onsuccesscallbackR, this.onfailureback); kony.application.settings.read("key2", this.onsuccesscallbackR, this.onfailurebackR); }, onfailureback: function(errorcode, errormessage) { alert("err is :" + errormessage); }, onsuccesscallbackR: function(key, value) { var params = {}; params.value = value; switch (value) { case "Table view": params.viewType = constants.SEGUI_VIEW_TYPE_TABLEVIEW; break; case "Page view": params.viewType = constants.SEGUI_VIEW_TYPE_PAGEVIEW; params.pageOffDotImage = "orngsld"; params.pageOnDotImage = "whitesld"; break; case "Coverflow view": params.viewType = constants.SEGUI_VIEW_TYPE_COVERFLOW; break; case "Cylinder view": params.viewType = constants.SEGUI_VIEW_TYPE_CYLINDER; break; case "Linear view": params.viewType = constants.SEGUI_VIEW_TYPE_LINEAR; break; case "Stack view": params.viewType = constants.SEGUI_VIEW_TYPE_STACK; break; } var ntf = new kony.mvc.Navigation("frmAppSetRead"); ntf.navigate(params); }, onfailurebackR: function(errorcode, errormessage) { alert("Err is :" + errormessage); }
Return Values
None.
Remarks
To use this API, you must create an appSettings.xml file
in the Project Workspace, and then add the code for the API in the file.
This function reads an app's settings from the settings file that is bundled with the application's binary. Your app can use this function to read, among other things, the user-defined values such as the preferred locations.
This is an asynchronous call so it returns immediately. Upon successfully reading the app's settings, the Quantum VisualizerAPI framework automatically invokes the callback your app passes in the onsuccesscallback parameter. The callback function has the following signature.
onsuccess(key, value);
When this callback function is invoked, the key parameter contains a string that specifies the name of the key whose value is being retrieved.
The value parameter contains the settings that were read. It can be Boolean
, string
, double
, or an object. It contains an object when Display option is set to multiselect.
If the Quantum VisualizerAPI framework cannot read the settings associated with the key parameter to the kony.application.settings.read
function, then the framework automatically invokes the function in the onfailurecallback parameter. The callback function has the following signature.
onfailure(errorcode,errormessage);
When the framework calls the onfailure
callback function errorcode parameter of contains a numeric error code and the errormessage parameter contains the corresponding error message as a string
.
Platform Availability
- iOS
This function enables your app to write values associated with specified keys.
Syntax
kony.application.settings.write(key, value, onsuccesscallback, onfailurecallback);
Input Parameters
Parameter | Description |
---|---|
key | A string that specifies the unique key. The key that you specify must exist. You cannot introduce a new key. |
value | A string that holds the value to be set for a key. If this function is called multiple times using the same key, existing value for the key is replaced with the new value. A key's value can be Boolean, string, double, or an object. It can contain an object only when Display option is set to multiselect. |
onsuccesscallback | The callback function that is executed when the new value is successfully assigned to the specified key. For details, see the Remarks section below. |
onfailurecallback | The callback function that is executed when there is an error in updating the configuration. This callback function receives an error code and an error message. For details, see the Remarks section below. |
Example
write: function() { var str1 = this.view.txtMsg.text + " "; var str2 = this.view.lstBxType.selectedKey; kony.application.settings.write("key1", str1, this.onsuccesscallbackw, this.onfailurebackw); kony.application.settings.write("key2", str2, this.onsuccesscallbackWrite, this.onfailurebackWrite); }, onsuccesscallbackw: function(key, value) { kony.print("Value is :" + value); }, onfailurebackw: function(errorcode, errormessage) { alert("Error is :" + errormessage); }, onsuccesscallbackWrite: function(key, value) { this.view.lblAppAfterSet.text = "App settings are successful"; }, onfailurebackWrite: function(errorcode, errormessage) { alert("Error is :" + errormessage); }
Return Values
None.
Remarks
To use this API, you must create an appSettings.xml file
in the Project Workspace, and then add the code for the API in the file.
This function sets the value of configuration options in the configuration file that is associated with the app. New keys cannot be introduced with this function. Your app can only write to existing keys. This is an asynchronous call, so it returns immediately and does not wait for the underlying hardware to write the value to the specified key. It uses callback functions to communicate success or failure. The callback functions for success and failure are set using this function's onsuccesscallback and onfailurecallback, respectively.
The callback function for the onsuccesscallback parameter of the kony.application.settings.write
function has the following syntax.
onsuccesscallback(key,value);
where the key
parameter to this callback is a string containing the name of the key that was set, and the callback function's value
parameter contains the value that the key was set to. The callback function's value
parameter can be boolean
, string
, double
, or an object. An object is only passed in through the value parameter when "Display option" is multiselect.
If the kony.application.settings.write
function cannot set the value of the specified key, in invokes another callback function. The callback function for the kony.application.settings.write
function's onfailurecallback parameter has the following syntax.
onfailurecallback(errorcode,errormessage);
where the errorcode
parameter contains a numeric error code and the errormessage
parameter holds a string that specifies the error message.
Platform Availability
- iOS