macOS SDK API reference
Module LicenseManagerKit, from the package licensemanager-swift. The reference generated from the source, with every documentation comment, is on the Swift Package Index .
LicenseManager
public final class LicenseManager: Sendable| Member | Description |
|---|---|
init(productID: String, publicKey: String, options: Options = Options()) throws(ConfigError) | Creates the manager and starts validating the stored key. See setup. |
var state: LicenseState | The current state. |
func ready() async -> LicenseState | The state once the startup validation is done, or right away with a valid stored token. Never throws. |
func setLicenseKey(_ key: String) async throws(LicenseError) -> LicenseState | Validates and stores a key the customer typed. See activation. |
func refresh() async -> LicenseState | Validates the stored key now. Never throws. See refresh. |
var states: AsyncStream<LicenseState> | The current state, then every change. Finishes on dispose(). |
func onStateChange(_ listener: @escaping @Sendable (LicenseState) -> Void) -> Subscription | Calls listener on every change, until the subscription is cancelled or released. |
var licenseKey: String? | The stored key, or nil. |
var portalURL: URL | Your product’s customer portal. |
var latestAllowedVersion: LatestAllowedVersion | In .versionNotAllowed: the latest version the license allows. |
var offlineState: OfflineState | Whether the last validation reached LicenseManager. See offline. |
func fingerprint() async -> String | This Mac’s fingerprint. |
var isClockTampered: Bool | The result of the latest clock check. |
func dispose() | Stops renewals, retries and the clock check. Idempotent; also done when the manager is released. |
static let sdkName: String | "licensemanager-swift". |
static let sdkVersion: String | The package’s version, like "1.0.0". |
LicenseManager.Options
public struct Options: Sendable {
public init(
fingerprint: MachineFingerprint? = nil,
version: String? = nil,
machineName: String? = nil,
platform: String? = nil,
minOfflineDuration: TimeInterval = 0,
keychainService: String? = nil,
useKeychain: Bool? = nil,
apiBaseURL: URL? = nil,
storageDirectories: [URL]? = nil
)
}Every property is a var with the same name. See options. apiBaseURL and storageDirectories are for tests.
LicenseManager.Subscription
public final class Subscription: Sendable {
public func cancel()
}Returned by onStateChange(_:). Cancelled by cancel(), or when released.
LicenseObserver
@MainActor public final class LicenseObserver: ObservableObject| Member | Description |
|---|---|
init(manager: LicenseManager) | Starts observing manager. |
let manager: LicenseManager | The observed manager. |
@Published var state: LicenseState | The current state. |
@Published var offlineState: OfflineState | The offline state. |
@Published var latestAllowedVersion: LatestAllowedVersion | The latest allowed version. |
@Published var licenseKeyHint: String? | The last 5 characters of the stored key. |
var portalURL: URL | The customer portal. |
func activate(key: String) async throws(LicenseError) -> LicenseState | setLicenseKey(_:) of the manager. |
func refresh() async | refresh() of the manager. |
func openPortal() | Opens the customer portal in the default browser. |
See SwiftUI and AppKit.
LicenseState
public enum LicenseState: String, Sendable, Codable, CaseIterable {
case loading = "LOADING"
case missingKey = "MISSING_KEY"
case active = "ACTIVE"
case invalidKey = "INVALID_KEY"
case expired = "EXPIRED"
case versionNotAllowed = "VERSION_NOT_ALLOWED"
case machineLimitReached = "MACHINE_LIMIT_REACHED"
case offlineExpired = "OFFLINE_EXPIRED"
case clockTampered = "CLOCK_TAMPERED"
}See license states.
OfflineState
public enum OfflineState: Sendable, Equatable {
case online
case offline(validUntil: Date?, remaining: TimeInterval)
}validUntil is the expiration of the stored token, nil without a valid token; remaining the seconds left. See offline state.
LatestAllowedVersion
public enum LatestAllowedVersion: Sendable, Equatable {
case notApplicable // not in .versionNotAllowed, or refused offline by the stored token
case noneAllowed // the license allows none of your releases
case version(String) // the latest version the license allows, like "2.3.1"
}LicenseError
public struct LicenseError: Error, Sendable, Equatable, LocalizedError {
public let code: Code
public let message: String
public let status: Int?
public let latestAllowedVersion: LatestAllowedVersion
public var isLocking: Bool { get }
public enum Code: String, Sendable, Codable, CaseIterable {
case notFound = "not_found"
case licenseExpired = "license_expired"
case versionNotAllowed = "version_not_allowed"
case machineLimitReached = "machine_limit_reached"
case planLimitExceeded = "plan_limit_exceeded"
case validationError = "validation_error"
case internalError = "internal_error"
case networkError = "network_error"
case invalidResponse = "invalid_response"
}
}See the errors.
ConfigError
public enum ConfigError: Error, Sendable, Equatable, LocalizedError {
case missingProductID
case missingPublicKey
case invalidPublicKey(String)
case missingVersion
}Thrown by LicenseManager.init. See what happens on creation.
MachineFingerprint
public enum MachineFingerprint: Sendable {
case value(String)
case provider(@Sendable () async -> String)
}The machine part of the fingerprint. See overriding the machine id.