Basic usage of the application-settings module in a component:
JavaScript
TypeScript
const appSettings =require("tns-core-modules/application-settings");functiononNavigatingTo(args){ appSettings.setBoolean("isTurnedOn",true); appSettings.setString("username","Wolfgang"); appSettings.setNumber("locationX",54.321);const isTurnedOn = appSettings.getBoolean("isTurnedOn");const username = appSettings.getString("username");const locationX = appSettings.getNumber("locationX");// Will return "No string value" if there is no value for "noSuchKey"const someKey = appSettings.getString("noSuchKey","No string value");// Will return false if there is no key with name "noSuchKey"const isKeExisting = appSettings.hasKey("noSuchKey");} exports.onNavigatingTo= onNavigatingTo;functiononClear(){// Removing a single entry via its key name appSettings.remove("isTurnedOn");// Clearing the whole application-settings for this app appSettings.clear();}
import{ getBoolean, setBoolean, getNumber, setNumber, getString, setString, hasKey, remove, clear }from"tns-core-modules/application-settings";exportfunctiononNavigatingTo(args){setBoolean("isTurnedOn",true);setString("username","Wolfgang");setNumber("locationX",54.321);const isTurnedOn:boolean=getBoolean("isTurnedOn");const username:string=getString("username");const locationX:number=getNumber("locationX");// Will return "No string value" if there is no value for "noSuchKey"const someKey:string=getString("noSuchKey","No string value");// Will return false if there is no key with name "noSuchKey"let isKeExisting:boolean=hasKey("noSuchKey");}functiononClear(){// Removing a single entry via its key nameremove("isTurnedOn");// Clearing the whole application-settings for this appclear();}