SDKs
...
Getting Started
Swift/Objective-C

Swift SDK Configuration and Usage

10min
swift sdk allows implementing licensing using the license and licensemanager classes this article has code samples for both approaches in the other ones, we will demonstrate sdk usage only with licensemanager and license licensehandler class has methods corresponding to license / licensemanager functionality configuration to initialize the sdk, you must fill in your application name and version, licensespring api key, shared key and product code both the api key and shared key can be found on your licensespring account under settings >keys api and shared key location your product code is located in your product list under configure products product coproduct code location location please, keep in mind that the product code field is case sensitive when you have the necessary values, create the configuration let configuration = configuration( apikey "xxxxxxxx xxxx xxxx xxxx xxxxxxxxxxxx", sharedkey "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", productcode "xx" ) configuration appname = "my licensespring application" configuration appversion = "1 0 0" now you can initialize licensemanager using this configuration object if apikey sharedkey or productcode is empty, the error is thrown licensemanager let manager = try licensemanager(configuration configuration) license activation the license keys are located in licenses section license key location to implement user based licensing please refer to user based licensing docid\ xepx04m3oh f6s8ylf6mz to activate a license, create a licenseid using the given key and call activation method licensemanager let license = try manager activatelicense(licensekey "xxxx xxxx xxxx xxxx") the process of activating a license refers to binding a device to a license on the licensespring platform, activating the license increments the total activations counter within the license local license the local license is a copy of the license information that is saved on the end user's local computer users who have not activated the license on their end before will not have a local license by default, the local license is stored /library/application support/\<process name>/\<product code>/license ls license key path and license key name may be customized through configuration see local license file docid\ fkfzhha n838tznrzu0sz for more information if a device already has a license, and you try to activate another license on that device, for the same product, that newly activated license will override the existing license, deleting it from the device this will be on the developer to make sure that they check if a license exists on the device before a new activation licensemanager if let license = manager currentlicense { } license check it is recommended to perform a local license check at application start to confirm that the local license file belongs to the current device and has not been transferred it is also useful to check whether the local license file has been tampered with and whether the local license is still valid license try license localcheck() //throws in case of errors full check (online check) license check performs synchronization of local license with the data from licensespring backend license try license fullcheck() //throws in case of errors this methods also updates information of installationfile for more information about managing software updates, see handling product versions docid\ zvfcf4 5cq4uj4dnsovbb you can also check for active, valid, enabled, and expired licenses using isactive , isvalid , isenabled , and isexpired methods respectively note that an active license does not necessarily mean a license is valid a valid license means the license is active, enabled, and not expired an active license means that the license is bound to a device, but may also be disabled or expired full code sample below you can find a code sample that initializes the sdk, retrieves a local license or activates a new one, and performs the necessary checks licensemanager do { let configuration = configuration( apikey "xxxxxxxx xxxx xxxx xxxx xxxxxxxxxxxx", sharedkey "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", productcode "xx" ) configuration appname = "my licensespring application" configuration appversion = "1 0 0" let manager = try licensemanager(configuration configuration) let license = try manager activatelicense(licensekey "xxxx xxxx xxxx xxxx") try license localcheck() try license fullcheck() } catch { print("error occured \\(error)") } license deactivation deactivating a license unbinds the device from the license, and decrements the number of total activations depending on the license transfer policy, this usually means that the license is freed up to be activated onto a new device deactivating is done using the following method license try license deactivate() to remove local license file after the deactivation use licensemanager clearlocalstorage method