# Quickstart

iOSparkle adds over-the-air (OTA) self-updates to the development builds of an iOS or iPadOS app. The library never reaches the App Store build: only a development variant links it, every use sits behind an explicit compilation condition, and the **App Store Audit** proves the shipping archive contains zero residue.

The whole integration is five steps:

1. [Choose an isolation pattern](#1-choose-an-isolation-pattern)
2. [Gate every use with `#if IOSPARKLE_ENABLED`](#2-the-red-line-if-iosparkle_enabled)
3. [Wire three lines of code](#3-wire-it-up)
4. [Publish the first build to a Channel](#4-publish-the-first-build)
5. [Run the App Store Audit](#5-run-the-app-store-audit-mandatory)

## What you need

- Xcode 16 or later. The package uses `swift-tools-version: 6.0` and supports iOS 16.0 and later.
- An Apple Developer team and a device you can run on from Xcode. OTA installation needs a Development or Ad Hoc profile that lists the device, so App Store signing cannot be used for the builds you publish.
- An HTTPS location that can serve four static files. Any static host works; see [Self-Hosting & Private Channels](self-hosting.md).
- The `iosparkle` command-line tool (macOS 13 or later). Until a release binary is published, build it from a checkout of this repository:

  ```sh
  swift build -c release --package-path cli
  # binary: cli/.build/release/iosparkle
  ```

Throughout this chapter the shipping app is `MyApp` (`com.example.myapp`), the development app is `MyAppDev` (`com.example.myapp.dev`), and the Channel lives at `https://ota.example.com/my-app-dev/`.

## 1. Choose an isolation pattern

Both patterns keep iOSparkle out of `MyApp` entirely. Pick one.

### Dual-Target Isolation (recommended)

Two app targets share one set of sources. Only the development target declares the `iOSparkle` package dependency.

| | `MyApp` (ships to the App Store) | `MyAppDev` (receives OTA updates) |
| --- | --- | --- |
| Sources | shared | shared |
| Bundle identifier | `com.example.myapp` | `com.example.myapp.dev` |
| `iOSparkle` package dependency | none | linked |
| `SWIFT_ACTIVE_COMPILATION_CONDITIONS` (Debug and Release) | *(unchanged)* | `$(inherited) IOSPARKLE_ENABLED` |

To set it up in Xcode:

1. Select the `MyApp` target and choose **Edit ▸ Duplicate**, then **Duplicate Only**. Rename the copy to `MyAppDev` and change its bundle identifier to `com.example.myapp.dev`.
2. Choose **File ▸ Add Package Dependencies…**, add the `iOSparkle` package (`https://github.com/justinyanme/iOSparkle.git`), and under **Add to Target** select `MyAppDev` only.
3. In the build settings of `MyAppDev`, set **Swift Active Compilation Conditions** to `$(inherited) IOSPARKLE_ENABLED` for **both** `Debug` and `Release`. Leave `MyApp` untouched.

`MyAppDev` is a normal app target: give it its own icon and display name so both apps are distinguishable on a device.

### Single-Target Multi-Configuration

When a second target is not an option, keep one target and add a configuration for OTA builds.

1. In the project editor, select the project, then **Info ▸ Configurations**. Duplicate `Release` and name the copy `DevOTA`. It inherits `-O` from `Release`.
2. Add the `iOSparkle` package dependency to the target.
3. Set these build settings on the target:

| Setting | `Debug` | `DevOTA` | `Release` |
| --- | --- | --- | --- |
| `SWIFT_ACTIVE_COMPILATION_CONDITIONS` | `$(inherited) DEBUG IOSPARKLE_ENABLED` | `IOSPARKLE_ENABLED` | *(must not contain `IOSPARKLE_ENABLED`)* |
| `PRODUCT_BUNDLE_IDENTIFIER` | `com.example.myapp.dev` | `com.example.myapp.dev` | `com.example.myapp` |
| `EXCLUDED_SOURCE_FILE_NAMES` | — | — | `iOSparkle.o` |

In Xcode's conditional notation:

```text
SWIFT_ACTIVE_COMPILATION_CONDITIONS[config=Debug]   = $(inherited) DEBUG IOSPARKLE_ENABLED
SWIFT_ACTIVE_COMPILATION_CONDITIONS[config=DevOTA]  = IOSPARKLE_ENABLED
PRODUCT_BUNDLE_IDENTIFIER[config=Debug]             = com.example.myapp.dev
PRODUCT_BUNDLE_IDENTIFIER[config=DevOTA]            = com.example.myapp.dev
EXCLUDED_SOURCE_FILE_NAMES[config=Release]          = iOSparkle.o
```

`Debug` links iOSparkle too, so it takes the `.dev` identifier as well: with the App Store identifier it would fetch a Feed whose `bundleId` it can never match, and it would clash with the App Store build on a device.

`Release` still sees the package dependency, so the `iOSparkle` module is compiled, but the whole library is one SwiftPM target that Xcode compiles to a single object file, `iOSparkle.o`. Excluding that one file from `Release` leaves nothing to link and nothing to embed. The App Store Audit in [step 5](#5-run-the-app-store-audit-mandatory) verifies this on every archive.

### Why a separate `.dev` bundle identifier

iOS refuses to install an OTA package over an app with the same bundle identifier unless the installed app was itself installed with a provisioning profile. An App Store or TestFlight build was not, so with one shared identifier:

- A tester who has the App Store build must delete it, losing all local data, before the OTA build can install.
- The App Store build and the OTA build can never coexist on one device.

With `com.example.myapp.dev`, both apps sit side by side, and each OTA update replaces the previous OTA build in place, keeping the app container. Use the `.dev` identifier for every configuration that links iOSparkle.

## 2. The red line: `#if IOSPARKLE_ENABLED`

Every `import iOSparkle` and every use of its types goes inside the explicit condition:

```swift
#if IOSPARKLE_ENABLED
import iOSparkle
#endif
```

The condition must be one you define yourself, only for the development variant: `IOSPARKLE_ENABLED`, or a development flag your project already has.

**Never gate iOSparkle with a bare `#if canImport(iOSparkle)`.** Xcode adds the build products directory to the module search path of every target that shares it. After any build of `MyAppDev`, `iOSparkle.swiftmodule` is still there, so `MyApp` — which does not link `iOSparkle.o` — evaluates `canImport(iOSparkle)` as `true`:

- In `Debug`, `MyApp` fails to link with `Undefined symbols`.
- In `Release` (`-O`, whole-module optimization), the compiler reads the serialized SIL of that stale module and inlines iOSparkle code across the module boundary, including the `itms-services://?action=download-manifest&url=` literal, straight into the shipping binary. Depending on what the gated code touches, you get a link error or, worse, a build that exits `0` without a single warning and ships App Store residue that only the App Store Audit catches.

An explicit condition cannot misfire this way: it is defined by the build settings of the development variant alone.

## 3. Wire it up

Three lines do the work. `IOSparkleUpdater` is `@MainActor`-isolated, so create it in a main-actor type: a SwiftUI `App` or `View`, a `UIResponder` subclass such as a scene delegate, or a type you mark `@MainActor` yourself.

### SwiftUI

```swift
import SwiftUI

#if IOSPARKLE_ENABLED
import iOSparkle

@MainActor
enum Updates {
    static let updater = IOSparkleUpdater(channelURL: URL(string: "https://ota.example.com/my-app-dev")!)  // 1
}
#endif

@main
struct MyAppDevApp: App {
    var body: some Scene {
        WindowGroup {
            ContentView()
                #if IOSPARKLE_ENABLED
                .iOSparkleUpdater(Updates.updater)  // 2: starts automatic checks when the view appears
                #endif
        }
    }
}

struct SettingsView: View {
    var body: some View {
        Form {
            #if IOSPARKLE_ENABLED
            IOSparkleDebugSection(updater: Updates.updater)  // 3: status, Update / Reinstall, diagnostics
            #endif
        }
    }
}
```

`.iOSparkleUpdater(_:)` calls `startAutomaticChecks()` when the view appears; from then on the updater observes scene activation itself. `IOSparkleDebugSection` is a `Section` for a `Form` or `List` and pushes its detail screen through a `NavigationStack`.

### UIKit

```swift
import UIKit

#if IOSPARKLE_ENABLED
import iOSparkle

@MainActor
enum Updates {
    static let updater = IOSparkleUpdater(channelURL: URL(string: "https://ota.example.com/my-app-dev")!)  // 1
}
#endif

final class SceneDelegate: UIResponder, UIWindowSceneDelegate {
    var window: UIWindow?

    func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options: UIScene.ConnectionOptions) {
        guard let windowScene = scene as? UIWindowScene else { return }
        let window = UIWindow(windowScene: windowScene)
        window.rootViewController = UINavigationController(rootViewController: SettingsViewController())
        self.window = window
        window.makeKeyAndVisible()
        #if IOSPARKLE_ENABLED
        Updates.updater.startAutomaticChecks()  // 2
        #endif
    }
}

final class SettingsViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()
        title = "Settings"
        navigationItem.rightBarButtonItem = UIBarButtonItem(
            title: "Developer Updates", style: .plain, target: self, action: #selector(showDeveloperUpdates)
        )
    }

    @objc private func showDeveloperUpdates() {
        #if IOSPARKLE_ENABLED
        navigationController?.pushViewController(  // 3: push inside a navigation controller
            IOSparkleDebugViewController(updater: Updates.updater), animated: true)
        #endif
    }
}
```

With that, a device running the `MyAppDev` Release build checks the Channel every time it comes to the foreground (at most once every 30 seconds), shows a system alert when a newer build is available, and installs it after the user taps **Update**. The **Developer Updates** screen shows the installed and published builds and offers **Check Now**, **Update**, and **Reinstall**.

To see it working on a device you run from Xcode, open **Developer Updates** and tap **Check Now**. Automatic alerts are deliberately off in Debug builds; [Troubleshooting](troubleshooting.md) explains every case where the updater stays silent on purpose.

The [Host App SDK & Headless API](client-sdk.md) chapter covers configuration (private Channel headers, a busy flag, an exit hook) and replacing the built-in alert with your own UI.

## 4. Publish the first build

Publish builds that were archived from `MyAppDev` with the **Release** configuration (or `DevOTA` in the single-target setup). A `-O` build installed from the Channel is the variant the updater treats as production: automatic checks are on.

1. Reserve the build number, then build with it.

   ```sh
   CHANNEL=https://ota.example.com/my-app-dev
   BUILD=$(iosparkle next-build --channel-url "$CHANNEL")     # 1 for a new Channel
   ```

   ```sh
   xcodebuild -project MyApp.xcodeproj -scheme MyAppDev -configuration Release \
     -derivedDataPath build/DerivedData -archivePath build/MyAppDev.xcarchive \
     archive CURRENT_PROJECT_VERSION="$BUILD"
   ```

2. Export an IPA signed for development. `ExportOptions.plist`:

   ```xml
   <?xml version="1.0" encoding="UTF-8"?>
   <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
   <plist version="1.0">
   <dict>
     <key>method</key>
     <string>development</string>
     <key>signingStyle</key>
     <string>automatic</string>
     <key>teamID</key>
     <string>YOURTEAMID</string>
   </dict>
   </plist>
   ```

   ```sh
   xcodebuild -archivePath build/MyAppDev.xcarchive -exportPath build/MyAppDev \
     -exportOptionsPlist ExportOptions.plist exportArchive
   ```

   Use `release-testing` as the method for an Ad Hoc export. An App Store export has no device list and cannot be installed over the air; `iosparkle publish` rejects it.

3. Publish. Everything is generated on your Mac; the destination only stores files.

   ```sh
   iosparkle publish --ipa build/MyAppDev/MyAppDev.ipa --channel-url "$CHANNEL" \
     --out ./channel --commit "$GIT_COMMIT" --notes-file notes.txt
   ```

   Upload `./channel` to the Channel location, or let `publish` do it over SSH with `--ssh deploy@ota.example.com:/var/www/ota/my-app-dev` instead of `--out`.

4. Verify end to end.

   ```sh
   iosparkle verify --channel-url "$CHANNEL" --ipa build/MyAppDev/MyAppDev.ipa
   ```

5. Install once on a device by opening `https://ota.example.com/my-app-dev/` in Safari and tapping **Install**. Every later update arrives through the app.

The Channel directory, the Feed file, and the install manifest are specified in [Static Feed & Channel Spec](channel-and-feed-spec.md); every command and flag is in [CLI & App Store Audit](cli-and-audit.md).

## 5. Run the App Store Audit (mandatory)

The integration is done only when the shipping archive passes the App Store Audit. Archive `MyAppDev` first and `MyApp` afterwards in the same `DerivedData`, and make both archives share one products directory. Xcode normally gives each archive its own, which would hide the `iOSparkle.swiftmodule` that `MyAppDev` leaves behind; with a shared directory, `MyApp` compiles right beside it — the situation in which a bare `canImport` misfires — and the audit still runs on a real archive, stripped and with its dSYMs. This is the same gate the repository's own CI runs.

```sh
DD="$(pwd)/build/DerivedData"                  # absolute: package build steps run from the package's own directory
PRODUCTS="$DD/Build/Products/iphoneos"         # one products directory for both archives
archive() {
  xcodebuild -quiet -project MyApp.xcodeproj -scheme "$1" -configuration "$2" \
    -destination 'generic/platform=iOS' -derivedDataPath "$DD" -archivePath "build/$1-$2.xcarchive" \
    CONFIGURATION_BUILD_DIR="$PRODUCTS" \
    'DWARF_DSYM_FOLDER_PATH=$(BUILD_DIR)/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)' \
    CODE_SIGNING_ALLOWED=NO archive
}

rm -rf build/*.xcarchive                       # never audit a stale artifact
archive MyAppDev Release                       # leaves iOSparkle.swiftmodule in $PRODUCTS
archive MyApp Release                          # must build, and stay clean, beside it

iosparkle audit-appstore build/MyApp-Release.xcarchive && echo "zero residue"
```

Both archives must exit `0` before anything is audited: a failed link step leaves an incomplete `.app` behind, and an audit of that leftover passes for the wrong reason. `CODE_SIGNING_ALLOWED=NO` skips signing, which the audit does not need. The `DWARF_DSYM_FOLDER_PATH` line keeps each archive's dSYMs where Xcode collects them, so audit the `.xcarchive` rather than an exported `.ipa` and the symbol check runs too. In the single-target setup, archive the one scheme with `archive MyApp DevOTA` first.

As a sanity check that the audit is not blind, run it on the development archive as well: `iosparkle audit-appstore build/MyAppDev-Release.xcarchive` must **fail**.

Repeat this gate on every change to targets, configurations, or package dependencies. The [CLI & App Store Audit](cli-and-audit.md) chapter describes the five checks, and a ready-made workflow for coding agents is in [`skills/iosparkle-integrate`](../skills/iosparkle-integrate/SKILL.md).
