---
title: "How to add license activation to a Mac app"
description: "Activate a Mac app against a purchase with an emailed code, verify the signed license offline in Swift, re-check it monthly, and let buyers move it to another Mac."
url: "https://deliverykit.app/guides/add-license-activation-to-a-mac-app"
updated: 2026-11-22
---

# How to add license activation to a Mac app

Activate a Mac app against a purchase with an emailed code, verify the signed license offline in Swift, re-check it monthly, and let buyers move it to another Mac.

Selling a Mac app outside the App Store means answering one question yourself: has this person paid? DeliveryKit answers it with a short exchange. The buyer types the email they paid with, gets a six-digit code, and your app receives a signed license it can check on its own from then on. There are no accounts, passwords or license keys to paste.

This guide adds that to a Swift app. It uses a made-up app called Kite. Every call is described in full in the [licensing API reference](https://deliverykit.app/guides/mac-app-licensing-api).

## 1. Turn on activation for the app

Create a file in DeliveryKit, choose **Mac app**, upload your disk image, and include the file in a product. On the file, turn on **Require activation** and set **Devices per purchase**.

The file's settings then show three things to copy into your app:

- the **API address**, such as `https://deliverykit.app/api/apps/your-studio/01m7f3…`
- the **public key** that verifies licenses
- the list of calls

## 2. Give each Mac an ID

The API needs a stable string for this Mac. Make one the first time the app runs and keep it:

```swift
let deviceID: String = {
    if let saved = UserDefaults.standard.string(forKey: "deviceID") { return saved }
    let made = UUID().uuidString
    UserDefaults.standard.set(made, forKey: "deviceID")
    return made
}()
```

## 3. Ask for a code, then activate

Two requests. The first emails the code:

```swift
let api = URL(string: "https://deliverykit.app/api/apps/your-studio/01m7f3…")!

func post(_ path: String, _ body: [String: String]) async throws -> (Data, HTTPURLResponse) {
    var request = URLRequest(url: api.appendingPathComponent(path))
    request.httpMethod = "POST"
    request.setValue("application/json", forHTTPHeaderField: "Content-Type")
    request.setValue("application/json", forHTTPHeaderField: "Accept")
    request.httpBody = try JSONEncoder().encode(body)
    let (data, response) = try await URLSession.shared.data(for: request)
    return (data, response as! HTTPURLResponse)
}

try await post("activation/request", ["email": email])
```

The answer is the same whether or not the address has bought the app, so show "Check your email" either way.

The second trades the code for a license:

```swift
struct Issued: Decodable { let license: String; let expires_at: String }

let (data, response) = try await post("activation", [
    "email": email,
    "code": code,
    "device_id": deviceID,
    "device_name": Host.current().localizedName ?? "Mac",
])
guard response.statusCode == 200 else { /* show the message under errors.code or errors.device */ return }
let issued = try JSONDecoder().decode(Issued.self, from: data)
UserDefaults.standard.set(issued.license, forKey: "license")
```

A `422` means the code was wrong or expired, the address has no current access, or the purchase is already on as many Macs as you allow. The response says which, in words you can show the buyer.

## 4. Verify the license on the Mac

A license is `claims.signature`, both base64url. The signature is Ed25519 over the first string, so CryptoKit can check it with the public key you copied.

One key signs every license in your workspace, so a good signature is not enough on its own. Check that the license is for this app and for this Mac too: `app` is the app's ID, and `dev` is the SHA-256 of the app's ID, a `|`, and the device ID, in hex.

```swift
import CryptoKit

let appID = "01m7f3…" // the last part of the API address

struct Claims: Decodable { let typ: String; let app: String; let dev: String; let exp: TimeInterval }

func base64url(_ text: Substring) -> Data? {
    var s = text.replacingOccurrences(of: "-", with: "+").replacingOccurrences(of: "_", with: "/")
    while s.count % 4 != 0 { s += "=" }
    return Data(base64Encoded: s)
}

func claims(of license: String, publicKey: String) -> Claims? {
    let parts = license.split(separator: ".")
    guard parts.count == 2,
          let signature = base64url(parts[1]),
          let body = base64url(parts[0]),
          let keyData = Data(base64Encoded: publicKey),
          let key = try? Curve25519.Signing.PublicKey(rawRepresentation: keyData),
          key.isValidSignature(signature, for: Data(parts[0].utf8)),
          let claims = try? JSONDecoder().decode(Claims.self, from: body),
          claims.exp > Date().timeIntervalSince1970,
          claims.app == appID,
          claims.dev == SHA256.hash(data: Data("\(appID)|\(deviceID)".utf8)).map({ String(format: "%02x", $0) }).joined()
    else { return nil }
    return claims
}
```

Run that at launch. If it returns claims, the app is unlocked, with no network call. `typ` tells you whether it is a `license` or a `trial`.

## 5. Re-check about once a month

A license lasts up to 45 days. Before it runs out, swap it for a fresh one:

```swift
let (data, response) = try await post("activation/refresh", ["license": license])
if response.statusCode == 200 {
    UserDefaults.standard.set(try JSONDecoder().decode(Issued.self, from: data).license, forKey: "license")
} else if response.statusCode == 403 {
    struct Refused: Decodable { let reason: String }
    let reason = (try? JSONDecoder().decode(Refused.self, from: data))?.reason
    UserDefaults.standard.set(true, forKey: "locked")
    if reason != "subscription_ended" {
        UserDefaults.standard.removeObject(forKey: "license") // refunded or deactivated
    }
}
```

Only a `403` should lock the app. If the Mac is offline, keep the license it has until it expires.

When the reason is `subscription_ended`, lock the app but keep the license. It is what `activation/renewal` takes to offer the buyer their own renewal, and after they renew, the same license refreshes again with no new code. Clear `locked` when a refresh next succeeds.

## 6. Let buyers move to another Mac

Add a **Deactivate** button that sends the license to `activation/deactivate` and forgets it. That frees the slot at once. You can also free a device yourself from the app file's page, which helps when a buyer's old Mac is gone.

## 7. Offer a renewal when paid time runs out

If you sell Kite by the year or as a subscription, ask `activation/renewal` when the license is close to its end. It returns the end date and a link that opens the buyer's own renewal, with their email already filled in and any returning-buyer discount applied. Open that link from a "Renew" button.

## Related

- [Mac app licensing API reference](https://deliverykit.app/guides/mac-app-licensing-api)
- [How to offer a free trial for a Mac app](https://deliverykit.app/guides/free-trials-for-mac-apps)
- [How to ship Mac app updates with Sparkle](https://deliverykit.app/guides/sparkle-updates-for-mac-apps)

Start selling your first download: [Get started](https://deliverykit.app/login?screen_hint=sign-up)
