Integrating padLOCK into your macOS application

Create product, install the SDK in your app, start using it.

Create your product

First, create a new product here. This will generate the required identifiers, API keys, etc, to use in the SDK setup later.

Install the SDK in your macOS app

The padLOCK xcframework is ditributed through SPM. Open your xcode project, navigate to your project, press "Package Dependencies" and add a new one. Use the following URL:

https://jontelang@bitbucket.org/jontelang/padlock-sdk-package.git

It will install the Padlock SDK, as well as the dependencies. KeychainAccess, used to store license key in Keychain, and CryptoSwift, used to decrypt license key files.

Setup the SDK

Now, you should be able to do import Padlock to import the SDK.

Navigate to your product and copy the product ID.

Create a new instance of the PadlockManager with the URL of the API. During DEVELOPMENT ONLY you can call the API endpoints directly, however for a production release, it is recommended to use a simple forward service to hide your API KEY. More on that later.

let padlock = PadlockManager(url: URL(string: "https://padlocksdk.com/api/v1/{YOUR_PRODUCT_ID}/license")!)

Checking license

To check your license keys within your app, you use this simple function:

padlock.evaluateLicense { result in
    switch result {
    case .valid(license: let license): print("Do your logic for a valid license here"); break
    case .noLicenseFound(reason: let reason): print("Do your logic for unlicensed use here"); break
    case .killed: print("TODO: Remove killed status"); break
    }
}

Initially, the product will have no license keys, and no license file downloaded through the SDK. This will result

Displaying the license key activation view

First, generate a test license key in your product page (Your product > License Keys > Generate) and add and email with it (this will activate the key).

Next, we will open the Padlock provided window for license key activation. To do this, you can do something like this:

func openLicense() {
    let window = padlock.getActivateOrBuyWindow() // You can display the window in any way you want.
    let controller = NSWindowController(window: window)
    NSApp.activate(ignoringOtherApps: true)
    controller.showWindow(self)
}

If everything is setup correctly, entering the email and key should display a success message, and all of your future padlock.evaluate { .. } function calls should now result in a valid license path.