naviapps/license-kit-setapp
Use LicenseKit in Setapp-distributed
Requirements
- iOS 15 or later, or macOS 12 or later
- Swift 5.10 or later
- A Setapp-integrated app that supplies whether Setapp currently allows access
Installation
Add the packages with Swift Package Manager:
.package(url: "https://github.com/naviapps/license-kit.git", from: "1.2.0"),
.package(url: "https://github.com/naviapps/license-kit-setapp.git", from: "1.0.0")Then depend on the products:
.product(name: "LicenseKit", package: "license-kit"),
.product(name: "LicenseKitSetapp", package: "license-kit-setapp")How It Works
Setapp does not give users a license key. For Setapp builds, activate LicenseKit with .automatic and let SetappLicenseProvider map the app's current Setapp access into a LicenseKit activation.
SetappLicenseProvider creates activations with:
source:SetappLicenseProvider.licenseSourceplanID:SetappLicenseProvider.planIDlicenseKey:nilactivationID:nilexpiresAt:nil
During validation, the provider reads the latest access state from your hasAccess closure. Return false when Setapp definitively denies access. Throw when the access check cannot complete so LicenseKit can apply its refresh failure and grace-period policy.
Use .automatic to create or replace the stored LicenseKit activation for a Setapp build. Use manager.refresh() later when your app wants LicenseKit to re-check the latest Setapp access state for an existing activation.
Usage
First, keep Setapp integrated in your app. Then pass only whether the current Setapp state allows access into SetappLicenseProvider.
currentSetappAccess() and activationStorage below are placeholders for app-owned code. Read the Setapp state with the Setapp Framework in your app, then return whether the app currently has access.
import LicenseKit
import LicenseKitSetapp
import Setapp // Your app's Setapp integration
let provider = SetappLicenseProvider(hasAccess: {
try await currentSetappAccess()
})
let manager = LicenseManager(
provider: provider,
activationStorage: activationStorage
)
try await manager.activate(.automatic)The provider does not persist Setapp account data. Persist LicenseKit activation state through your LicenseActivationStorage, and wire LicenseKit's current license state into your UI.
Use manager.refresh() when your app wants LicenseKit to re-check the latest Setapp access state through the provider.
Typical Flow
- Initialize Setapp in your app.
- Read whether Setapp currently allows access.
- Pass that access state into
SetappLicenseProvider. - Activate LicenseKit with
.automaticfor the Setapp build. - Refresh LicenseKit when the Setapp access state changes or needs re-checking.
For non-Setapp builds, use the provider package that matches that distribution channel and activate with the request shape it expects, such as a license-key request for a license-key provider. Setapp builds should use SetappLicenseProvider with .automatic.
Checking License State
Setapp account or access checks stay in your app. LicenseKitSetapp receives only the current access state and maps it into LicenseKit state.
Use LicenseKit's state to decide whether licensed functionality should be available:
let state = try await manager.activate(.automatic)
if state.isLicensed {
// Enable licensed functionality.
}When your app wants to re-check the current Setapp access state, refresh the manager and read the returned state:
let result = try await manager.refresh()
if result.state.isLicensed {
// The latest Setapp access state is still usable.
}App-Owned Responsibilities
Your app remains responsible for:
- Setapp Framework initialization
- Setapp access monitoring
- app lifecycle hooks
- LicenseKit activation storage
- UI state and messaging
- Setapp review and distribution requirements
See Setapp's documentation for Setapp Framework initialization and subscription monitoring details:
Documentation
The package includes a DocC overview for the public API surface under Sources/LicenseKitSetapp/Documentation.docc.
Security
Do not log or commit private Setapp account, receipt, or diagnostic data. This package does not require app secrets or store private customer data. Report vulnerabilities through the process in SECURITY.md.
License
LicenseKitSetapp is available under the MIT License. See LICENSE.
Package Metadata
Repository: naviapps/license-kit-setapp
Default branch: main
README: README.md