Skip to Content
macOS (Swift)API reference

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
MemberDescription
init(productID: String, publicKey: String, options: Options = Options()) throws(ConfigError)Creates the manager and starts validating the stored key. See setup.
var state: LicenseStateThe current state.
func ready() async -> LicenseStateThe state once the startup validation is done, or right away with a valid stored token. Never throws.
func setLicenseKey(_ key: String) async throws(LicenseError) -> LicenseStateValidates and stores a key the customer typed. See activation.
func refresh() async -> LicenseStateValidates 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) -> SubscriptionCalls listener on every change, until the subscription is cancelled or released.
var licenseKey: String?The stored key, or nil.
var portalURL: URLYour product’s customer portal.
var latestAllowedVersion: LatestAllowedVersionIn .versionNotAllowed: the latest version the license allows.
var offlineState: OfflineStateWhether the last validation reached LicenseManager. See offline.
func fingerprint() async -> StringThis Mac’s fingerprint.
var isClockTampered: BoolThe 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: StringThe 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
MemberDescription
init(manager: LicenseManager)Starts observing manager.
let manager: LicenseManagerThe observed manager.
@Published var state: LicenseStateThe current state.
@Published var offlineState: OfflineStateThe offline state.
@Published var latestAllowedVersion: LatestAllowedVersionThe latest allowed version.
@Published var licenseKeyHint: String?The last 5 characters of the stored key.
var portalURL: URLThe customer portal.
func activate(key: String) async throws(LicenseError) -> LicenseStatesetLicenseKey(_:) of the manager.
func refresh() asyncrefresh() 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.