ApplicationSettings
The ApplicationSettings class allows you to store key/value pairs of data on the device. For example, an app could store a user’s auth state so that the user does not have to re-login when she resumes the app,if she didn’t log out when she left the app.
Setters
setString(key: string, value: string): void
Sets a String Object for a key.
You can use this method with the JSON.stringify()
to store an object or an array as a string and then use JSON.parse()
to convert the result of getString()
back to the object or array.
// simple string
ApplicationSettings.setString(key, "some string value")
//Storing an object
const obj = {key: "value"};
const objAsString = JSON.stringify(obj);// objAsString = '{"key":"value"}'
ApplicationSettings.setString("key", objAsString)
//Retrieve
const objStr = ApplicationSettings.getString("key");
comsy myObj = JSON.parse(ObjStr) // myObj = {key: 'value'}
Getters
getBoolean(key: string, defaultValue?: boolean): boolean
Gets a value (if existing) for a key as a Boolean Object. A default value can be provided in case there is no existing value.
getString(key: string, defaultValue?: string): string
Gets a value (if existing) for a key as a String Object. A default value can be provided in case there is no existing value.