SDKs
...
Tutorials
Best Practices
Device Variables Usage
10min
device variables play a crucial role in licensespring's sdks by facilitating the exchange of data from devices to the vendor platform this mechanism allows developers and administrators to gather real time device specific information, empowering them to make informed decisions and tailor licensing strategies based on accurate insights the aim of this section is to provide you with a comprehensive understanding of effectively utilizing device variables prerequisites completed the getting started docid\ lsfy9tq3vfq4roow9shkd tutorial, including initialized licensemanager (or licensehandler ) with your configuration using the appropriate settings created a licenseid using either licenseid fromkey or licenseid fromuser function, depending on the activation method you prefer activated a license of any type implemented routine local and online checks within the application understanding device variable usage some examples of scenarios where device variables are useful hardware specifications device variables can be utilized to capture and transmit hardware specifications, such as cpu type, ram size, and storage capacity this information can be invaluable for tailoring licenses based on the user's hardware capabilities tracking user registration data user registration data includes names and user information, which can be sent and kept track of on the licensespring platform using these variables this enables you to gather and manage essential user details directly within the licensing framework, streamlining administrative tasks and enhancing user experience user preferences store user preferences, settings, and configurations using device variables to create a more personalized and seamless user experience adding device variables integrating device variables is simple with the licensespring sdk, and on existing licenses can be done in three different ways adding a name value pair adding a devicevariable object adding multiple devicevariable objects via vector/array //1 license >adddevicevariable( "name", "value", false ); //2 devicevariable devicevar = devicevariable( "name", "value"); license >adddevicevariable( devicevar, false ); //3 std vector\<devicevariable> devicevariables = { devicevariable( "name1", "value1" ), devicevariable( "name2", "value2" ) }; license >adddevicevariables( devicevariables ); //finally, to send our variables to the licensespring server license >senddevicevariables();//1 license adddevicevariable("name", "value"); //2 devicevariable devicevariable = devicevariable("name", "value"); license adddevicevariable(devicevar); //3 devicevariable\[] devvariables = { new devicevariable( "name1", "value1" ), new devicevariable( "name2", "value2" ) }; license adddevicevariables(devvariables); //finally, to send our variables to the licensespring server license senddevicevariables(); swift try license senddevicevariables(\[ "name1" "value1", "name2" "value2" ])# 1,2,3 are directly supported within set device variables license set device variables({"a" "b","c" "d"}) \#send device variables to ls server license send device variables() // go sdk v2 	customfields = \[]core request customfields{} 	customfields = append(customfields, core request customfields{name "name", value "device1"}) 	err = lh senddevicedata(ctx, customfields) string licensekey = "\<sample key>"; string licenseidentity = licenseidentity fromkey(licensekey); devicevariables variables = devicevariables builder() variable("var1", "value1") variable("var2", "value2") build(); licensemanager trackvariables(licenseidentity, variables getvariables()); note to update a device variable, you can simply add the device variable with the same name, and it’s updated value device variables can also be set on license activation devicevariable\[] devicevariables = { new devicevariable("name1", "value1"), new devicevariable("name2", "value2") }; licenseid id = licenseid fromkey("license key goes here"); ilicense license = licensemanager activatelicense(id, devicevariables); // offline activation is also supported string offlineactivationfile = licensemanager getofflineactivationfile(id, devicevariables);std vector\<devicevariable> devicevariables = { {"name1", "value1"}, {"name2", "value2"} }; auto licenseid = licenseid fromkey("license key here"); auto license = licensemanager >activatelicense(licenseid, devicevariables) // offline activation is also supported std wstring offlineactivationfile = licensemanager >createofflineactivationfile(licenseid, devicevariables);# only supports offline acitvations req folder = "req folder path" lm create offline activation file(license id,req folder,device variables={"a" "b","c" "d"}) string licensekey = "\<sample key>"; string licenseidentity = licenseidentity fromkey(licensekey); devicevariables variables = devicevariables builder() variable("var1", "value1") variable("var2", "value2") build(); activateofflineparams params = activateofflineparams builder() variables(variables) build(); string file = licensemanager offlineactivationfile(licenseidentity, null, params); accessing device variables to locate the device variables through the vendor platform, first navigate to your license then to the "devices" tab device tab where device variables are found next, click on the device variables button to open a list of the device's device variables device variables button std vector\<devicevariable> device vec = license >getdevicevariables( true );devicevariable\[] devvariables = license getdevicevariables( true ); swift // just assess variables (updated after latest online check) let existingvariables = license devicevariables // request variables from the licensespring platform let updatedvariables = try license requestdevicevariables()device var list = license get device variables(get from be=true) print(device var list)// go sdk v2 vars, err = lh getdevicevariables(ctx, true)// offline retrieve device variables license license = licensemanager getcurrent(); licensedata data = license getdata(); list\<devicevariable> variables = data getvariables(); // online retrieve device variables licenseidentity identity = license getidentity(); list\<devicevariable> variables = licensemanager getvariables(identity); note the sdks have the ability to retrieve device variables from either the local license or from the backend the boolean that is passed as the parameter into the getdevicevariables function decides where they are retrieved from true gets the device variables from the backend, whereas false searches the local license by default, this false is set to false if no parameters are passed to this method, it will retrieve from the local license