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
API and Shared Key Location


Your product code is located in your product list under Configure Products:

Product CoProduct Code Location Location
Product Code Location


Please, keep in mind that the product code field is case-sensitive.

When you have the necessary values, create the Configuration.

Swift


Now you can initialize LicenseManager using this configuration object. If apiKey sharedKey or productCode is empty, the error is thrown.

LicenseManager


License Activation

The license keys are located in Licenses section:

License Key Location
License Key Location


To implement user-based licensing please refer to: User-Based Licensing.

To activate a license, create a LicenseID using the given key and call activation method.

LicenseManager


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 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


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


Full check (online check) license check performs synchronization of local license with the data from LicenseSpring backend:

License


This methods also updates information of InstallationFile. For more information about managing software updates, see Handling Product Versions.

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


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


To remove local license file after the deactivation use LicenseManager.clearLocalStorage method.