惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园 - 聂微东
MyScale Blog
MyScale Blog
The GitHub Blog
The GitHub Blog
C
Check Point Blog
M
MIT News - Artificial intelligence
U
Unit 42
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
H
Help Net Security
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
D
DataBreaches.Net
大猫的无限游戏
大猫的无限游戏
D
Docker
Last Week in AI
Last Week in AI
IT之家
IT之家
F
Fortinet All Blogs
A
About on SuperTechFans
P
Proofpoint News Feed
The Cloudflare Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
B
Blog RSS Feed
博客园_首页
月光博客
月光博客
博客园 - 司徒正美
Y
Y Combinator Blog

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
How to add license keys to a SwiftUI macOS app (in under ...
Nico · 2026-06-27 · via DEV Community

Nico

You built a Mac app, you want to sell it outside the App Store, and now you need licensing: a key the customer enters, an activation that sticks, and feature gates that hold up offline. Here's how to do it in an afternoon without standing up a backend.

Note: this is cross-posted from the Keylight blog. I build Keylight, so this uses it as the worked example — the shape of the solution applies whatever SDK you choose.

The three things licensing actually has to do

Strip away the marketing and every licensing system does exactly three jobs:

  1. Activate — turn a key the user pastes in into proof-of-purchase bound to this device.
  2. Verify — on every launch, confirm that proof is still valid, including offline.
  3. Gate — unlock features based on the tier/entitlements the license carries.

If you build this by hand you're writing a server, a crypto layer, and a state machine. The point of an SDK is to skip all three.

1. Add the SDK

Add the Swift package in Xcode (File ▸ Add Package Dependencies) pointing at the Keylight Swift SDK, then configure it once with your tenant key at app launch:

import Keylight

let keylight = Keylight(tenant: "your_tenant_key")

2. Activate a key

Give the user a text field and call activate. This is the one online step — it exchanges the key for a signed, device-bound lease that's stored locally:

do {
    try await keylight.activate(key: enteredKey)
    // lease stored — the app is now licensed on this device
} catch {
    // show the user why: invalid key, device limit reached, etc.
}

3. Verify on launch (offline-safe)

On every subsequent launch you don't hit the network. The SDK verifies the stored lease's Ed25519 signature locally and hands you a state:

switch keylight.checkOnLaunch() {
case .licensed(let lease):
    unlockApp(entitlements: lease.entitlements)
case .trial(let daysLeft):
    runTrial(daysLeft: daysLeft)
case .expired, .invalid:
    showActivationScreen()
}

No server call, so the app opens instantly and works on a plane. The lease carries a max-offline window; past it the SDK refreshes online once, which is also where a revoked or refunded license gets caught.

4. Gate features by entitlement

Because entitlements are signed inside the lease, feature gating is offline too. Don't scatter if licensed across your views — read entitlements once and drive your UI off them:

@Observable final class Licensing {
    var entitlements: Set<String> = []
    var isPro: Bool { entitlements.contains("pro") }
}

if licensing.isPro {
    ProExportButton()
} else {
    UpgradePrompt()
}

5. Get paid (the part people forget)

A license is only useful if buying one mints it. If you connect Stripe, a completed payment can mint the license automatically — no webhook code to write — so the customer's key works the moment they pay. That closes the loop: pay → key → activate → offline-verified Pro.

What you skipped by not building it yourself

A signing server, Ed25519 key management, lease parsing, device binding, a trial/expiry state machine, and Stripe webhook plumbing. That's the week-plus you just didn't spend.

Full docs and the free tier are at keylight.dev. If you're on Tauri or Electron instead of native Swift, the same SDK pattern exists in JS/Rust.