---
name: iosparkle-integrate
description: Add iOSparkle over-the-air self-update to an iOS Host App and prove zero residue in its App Store build. Use when adding in-app updates or OTA updates to a development build, wiring IOSparkleUpdater or the Developer Updates settings screen, creating a .dev target or DevOTA configuration behind an explicit compilation condition, or running iosparkle audit-appstore on a shipping archive.
---

# iOSparkle Integration

Make the development variant of a Host App update itself from a Channel, and prove that the App Store archive carries none of it. Five steps, in order. Each ends in a check; do not start the next step before the check passes.

Names throughout: the shipping app is `MyApp` (`com.example.myapp`), the development app is `MyAppDev` (`com.example.myapp.dev`), the Channel is `https://ota.example.com/my-app-dev/`. Substitute the project's real names.

## Rules that do not bend

- **Red line — an explicit condition.** Every `import iOSparkle` and every use of its types sits inside `#if IOSPARKLE_ENABLED` (or a development flag the project already defines), and that condition is set only in the build settings of the development variant. The condition is never `#if canImport(iOSparkle)`: once the development variant has been built, its `iOSparkle.swiftmodule` stays in the shared products directory, `canImport` turns `true` in the shipping target too, and that target does not link the library. `Debug` then fails to link; `Release` (`-O`) inlines the `itms-services://` literal across the module boundary and can exit `0` with no warning.
- **A `.dev` bundle identifier** on every target or configuration that links iOSparkle. iOS refuses to install an OTA package over an App Store build with the same identifier.
- **One updater, on the main actor.** `IOSparkleUpdater` is `@MainActor`: create it in a SwiftUI `App` or `View`, in a `UIResponder` subclass, or in a type marked `@MainActor`.
- **Done means audited.** `iosparkle audit-appstore` exits `0` on the shipping archive and exits non-zero on the development archive. A build that compiles is not done.

## 1. Survey the project

Find what defines targets, configurations, and dependencies, and read it.

| The project is defined by | Read |
| --- | --- |
| `MyApp.xcodeproj` (Xcode) | `xcodebuild -list`, then `-showBuildSettings` per scheme and configuration; `grep` `project.pbxproj` for `SwiftPackage`, `SWIFT_ACTIVE_COMPILATION_CONDITIONS`, `EXCLUDED_SOURCE_FILE_NAMES` |
| `project.yml` (XcodeGen) | `configs`, `packages`, and each target's `dependencies` and `settings` |
| `Project.swift` (Tuist) | `Project(name:packages:targets:)`: each target's `dependencies` and `settings`, and the project's `configurations` |

```sh
xcodebuild -list -project MyApp.xcodeproj
xcodebuild -showBuildSettings -project MyApp.xcodeproj -scheme MyApp -configuration Release \
  | grep -E 'PRODUCT_BUNDLE_IDENTIFIER|SWIFT_ACTIVE_COMPILATION_CONDITIONS|SWIFT_OPTIMIZATION_LEVEL|EXCLUDED_SOURCE_FILE_NAMES'
grep -nE 'SwiftPackage|SWIFT_ACTIVE_COMPILATION_CONDITIONS|EXCLUDED_SOURCE_FILE_NAMES' MyApp.xcodeproj/project.pbxproj
```

Also find: the app's entry point (SwiftUI `App`, or UIKit `AppDelegate` / `SceneDelegate`), its Settings screen, and any development flag the project already defines — a condition set only on a development target or configuration.

**Done when** a table has one row per target and configuration with its bundle identifier, `SWIFT_OPTIMIZATION_LEVEL`, compilation conditions, and whether iOSparkle is linked — and it names the shipping target, the development variant, and the condition to use.

## 2. Choose the isolation pattern

1. A second app target already serves as the development variant (its own bundle identifier, the app's sources): **Dual-Target**, using it.
2. No such target, and XcodeGen or Tuist generates the project: **Dual-Target**, adding an `<App>Dev` target (step 3 shows the declaration).
3. A hand-maintained `.xcodeproj` with a single target: **Single-Target**, adding a `DevOTA` configuration (step 3 provides the script).

**Done when** the pattern is chosen and three names are fixed: the development target or configuration, its `.dev` bundle identifier, and the condition.

## 3. Add the dependency and the condition

The package goes on the development variant only. The condition is defined for **both** `Debug` and `Release` of that variant — and for `DevOTA` where it exists — and for nothing else.

**XcodeGen** — `project.yml`:

```yaml
packages:
  iOSparkle:
    url: https://github.com/justinyanme/iOSparkle.git
    from: 0.1.0
configs: { Debug: debug, Release: release }
targets:
  MyApp:                                    # ships to the App Store: no iOSparkle dependency
    type: application
    platform: iOS
    sources: [MyApp]
    settings: { base: { PRODUCT_BUNDLE_IDENTIFIER: com.example.myapp } }
  MyAppDev:                                 # receives OTA updates
    type: application
    platform: iOS
    sources: [MyApp]
    dependencies: [package: iOSparkle]
    settings:
      base:
        PRODUCT_BUNDLE_IDENTIFIER: com.example.myapp.dev
        SWIFT_ACTIVE_COMPILATION_CONDITIONS: $(inherited) IOSPARKLE_ENABLED
```

**Tuist 4** — `Project.swift`:

```swift
import ProjectDescription

let project = Project(
    name: "MyApp",
    packages: [
        .package(url: "https://github.com/justinyanme/iOSparkle.git", .upToNextMajor(from: "0.1.0")),
    ],
    targets: [
        .target(                                   // ships to the App Store: no iOSparkle dependency
            name: "MyApp", destinations: .iOS, product: .app, bundleId: "com.example.myapp",
            infoPlist: .default, sources: ["Sources/**"]
        ),
        .target(                                   // receives OTA updates
            name: "MyAppDev", destinations: .iOS, product: .app, bundleId: "com.example.myapp.dev",
            infoPlist: .default, sources: ["Sources/**"],
            dependencies: [.package(product: "iOSparkle")],
            settings: .settings(base: ["SWIFT_ACTIVE_COMPILATION_CONDITIONS": "$(inherited) IOSPARKLE_ENABLED"])
        ),
    ]
)
```

**Plain `.xcodeproj`** — the `xcodeproj` Ruby gem (`gem install xcodeproj`) edits the project file reliably. Link the package into the development target only:

```ruby
# Usage: ruby add_iosparkle.rb MyApp.xcodeproj MyAppDev https://github.com/justinyanme/iOSparkle.git 0.1.0
require 'xcodeproj'

project_path, target_name, repository_url, minimum_version = ARGV
project = Xcodeproj::Project.open(project_path)
target = project.targets.find { |t| t.name == target_name } or abort "no target named #{target_name}"

reference = project.new(Xcodeproj::Project::Object::XCRemoteSwiftPackageReference)
reference.repositoryURL = repository_url
reference.requirement = { 'kind' => 'upToNextMajorVersion', 'minimumVersion' => minimum_version }
product = project.new(Xcodeproj::Project::Object::XCSwiftPackageProductDependency)
product.package = reference
product.product_name = 'iOSparkle'
target.package_product_dependencies << product
project.root_object.package_references << reference
build_file = project.new(Xcodeproj::Project::Object::PBXBuildFile)   # "iOSparkle in Frameworks"
build_file.product_ref = product
target.frameworks_build_phase.files << build_file
project.save
puts "linked iOSparkle into #{target_name}"
```

All three edits matter: the package reference, the product dependency on the target, and the build file in the target's Frameworks phase. Without the build file the package resolves but the build reports `Unable to resolve module dependency: 'iOSparkle'`.

For the Single-Target pattern, add the `DevOTA` configuration the same way. It clones `Release` for the project and every target, then wires the app target:

```ruby
# Usage: ruby add_devota.rb MyApp.xcodeproj MyApp com.example.myapp.dev
require 'xcodeproj'

project_path, target_name, dev_bundle_id = ARGV
project = Xcodeproj::Project.open(project_path)
target = project.targets.find { |t| t.name == target_name } or abort "no target named #{target_name}"
if project.build_configurations.map(&:name).include?('DevOTA') then abort 'DevOTA already exists' end

clone = lambda do |list|
  release = list.build_configurations.find { |c| c.name == 'Release' }
  devota = project.new(Xcodeproj::Project::Object::XCBuildConfiguration)
  devota.name = 'DevOTA'
  devota.build_settings = release.build_settings.dup      # a true clone of Release, -O included
  devota.base_configuration_reference = release.base_configuration_reference
  list.build_configurations << devota
end

# Adds the condition to a configuration, keeping every condition already there (DEBUG included),
# and gives it the .dev bundle identifier.
wire = lambda do |name|
  settings = target.build_settings(name)
  current = settings['SWIFT_ACTIVE_COMPILATION_CONDITIONS']
  conditions = current.nil? || current.to_s.strip.empty? ? ['$(inherited)'] : Array(current).flat_map { |value| value.to_s.split }
  conditions << 'IOSPARKLE_ENABLED' unless conditions.include?('IOSPARKLE_ENABLED')
  settings['SWIFT_ACTIVE_COMPILATION_CONDITIONS'] = conditions.join(' ')
  settings['PRODUCT_BUNDLE_IDENTIFIER'] = dev_bundle_id
end

clone.call(project.build_configuration_list)
project.targets.each { |t| clone.call(t.build_configuration_list) }
wire.call('Debug')
wire.call('DevOTA')
target.build_settings('Release')['EXCLUDED_SOURCE_FILE_NAMES'] = 'iOSparkle.o'
project.save
puts "added DevOTA to #{target_name}"
```

Every configuration that links iOSparkle leaves with the `.dev` bundle identifier — `Debug` included, because it fetches the Feed too — and with the condition appended to whatever conditions it already had.

The settings, per pattern and configuration:

| | `Debug` | `DevOTA` | `Release` |
| --- | --- | --- | --- |
| Dual-Target, development target | `$(inherited) IOSPARKLE_ENABLED` | — | `$(inherited) IOSPARKLE_ENABLED` |
| Dual-Target, shipping target | unchanged | — | unchanged — must not contain the condition |
| Single-Target | `IOSPARKLE_ENABLED` appended to the existing conditions (`DEBUG` stays), bundle ID `.dev` | `IOSPARKLE_ENABLED`, bundle ID `.dev` | unchanged; `EXCLUDED_SOURCE_FILE_NAMES = iOSparkle.o` |

`iOSparkle.o` is the single object file Xcode builds from the package. Excluding it from `Release` leaves the configuration with nothing to link. Use the project's own development flag in place of `IOSPARKLE_ENABLED` wherever the word appears above.

**Done when**
- `xcodebuild -resolvePackageDependencies` — or `tuist generate` / `xcodegen generate` — succeeds;
- `xcodebuild -showBuildSettings` lists the condition for every configuration of the development variant and for none of the shipping target;
- every configuration that links iOSparkle has a bundle identifier ending in `.dev` — in the Single-Target pattern that is `Debug` as well as `DevOTA`.

## 4. Wire the updater

SwiftUI — the three numbered lines are the integration:

```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
        }
    }
}
```

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
    }
}
```

From a UIKit screen, push `IOSparkleDebugViewController(updater: Updates.updater)` (3) on a navigation controller, inside the condition.

Place the snippets where the project's structure calls for them: the `Updates` enum in one file of the shared sources, the modifier on the root view, the section in Settings. The Channel URL is the development variant's Channel. Add configuration only when the Host App needs it — a private Channel's Feed token, a busy flag, an exit hook:

```swift
#if IOSPARKLE_ENABLED
import iOSparkle

@MainActor
enum Updates {
    private static let configuration = IOSparkleUpdater.Configuration(
        feedHeaders: ["Authorization": "Bearer <token>"],  // sent with every feed.json request; never reaches iOS's installer
        isBusy: { CheckoutFlow.isActive },                 // no alert while true
        beforeExitForInstall: { await Log.flush() }        // runs after the user taps Install, for at most 2 seconds
    )
    static let updater = IOSparkleUpdater(                 // line 1 of the wiring snippet, with configuration
        channelURL: URL(string: "https://ota.example.com/my-app-dev")!,
        configuration: configuration
    )
}
#endif
```

Declare the configuration in its own statement, as above. Written inline inside the `IOSparkleUpdater(…)` call, a `beforeExitForInstall` closure that awaits anything off the main actor is rejected by the Swift 6 compiler with `default argument cannot be both main actor-isolated and @concurrent`; the separate declaration compiles.

**Done when** both variants build with exit code `0`:

```sh
xcodebuild -project MyApp.xcodeproj -scheme MyAppDev -configuration Release -sdk iphoneos build CODE_SIGNING_ALLOWED=NO
xcodebuild -project MyApp.xcodeproj -scheme MyApp -configuration Release -sdk iphoneos build CODE_SIGNING_ALLOWED=NO
```

For the Single-Target pattern, use the one scheme with `-configuration DevOTA` and `-configuration Release`. If the shipping build fails here with `Undefined symbols` for iOSparkle symbols, some source is gated by `canImport(iOSparkle)`: return to step 3 and fix the condition. Step 5 is the authoritative check.

## 5. Pass the gate

The gate is the App Store Audit, run adversarially: the development archive is built first, and the shipping archive is built beside it, in one products directory. Xcode normally gives each archive its own products directory, which would hide the module the development variant left behind; `CONFIGURATION_BUILD_DIR` puts every archive in the same one. If `iosparkle` is not on `PATH`, build it from a checkout of the repository: `swift build -c release --package-path <checkout>/cli`.

```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 every archive
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                        # 1) leaves iOSparkle.swiftmodule and iOSparkle.o in $PRODUCTS
archive MyApp Release                           # 2) compiles beside them: a bare canImport misfires right here
```

Single-Target: one scheme — `archive MyApp DevOTA`, then `archive MyApp Release`. The `DWARF_DSYM_FOLDER_PATH` line keeps each archive's dSYMs where Xcode collects them, so the symbol check still runs.

Both archives must exit `0` before anything is audited. A failed link step leaves an incomplete bundle behind, and an audit of that leftover passes for the wrong reason. Then audit both archives, which carry all five checks — a stripped binary and its dSYMs:

```sh
iosparkle audit-appstore build/MyApp-Release.xcarchive;    echo "shipping: exit $?"     # must print 0
iosparkle audit-appstore build/MyAppDev-Release.xcarchive; echo "development: exit $?"  # must print a non-zero code
```

| Result | Meaning | Action |
| --- | --- | --- |
| shipping `0`, development non-zero | Zero residue in the archive that was compiled beside the development products, and the audit is not blind. | Done. |
| shipping fails with `Found N raw byte match(es)` or `Found iOSparkle symbol` | iOSparkle code reached the shipping binary. | Look for a bare `#if canImport(iOSparkle)`, the condition set on the shipping configuration, the package linked to the shipping target, or — Single-Target — a missing or misspelled `EXCLUDED_SOURCE_FILE_NAMES`. Fix it in steps 3–4 and rerun the gate. |
| shipping fails with `Remove itms-services from LSApplicationQueriesSchemes` | The shipping `Info.plist` declares the scheme. | Delete the declaration; iOSparkle does not need it. |
| shipping fails with `Bundle entry name contains iOSparkle` | An iOSparkle framework or bundle is embedded in the shipping app. | Remove it from the shipping target's *Frameworks* and *Copy Bundle Resources*. |
| shipping fails with `ProvisionedDevices is present` | A development-signed archive was audited. | Keep `CODE_SIGNING_ALLOWED=NO`, or archive with App Store signing. |
| the shipping archive fails to build, with `Undefined symbols` for iOSparkle symbols | The same residue, caught one step earlier: the shipping target compiled iOSparkle code from the leftover module. | Replace the condition (steps 3–4), then rerun the gate. |
| development passes | The development variant does not contain iOSparkle. | The condition is missing from the development configuration, or the updater code is not compiled in. Fix steps 3–4; the gate proves nothing until this archive fails. |
| any other build failure | Nothing may be audited yet. | Fix the build, delete the leftover artifacts, and rerun the gate. |

**Done when** the shipping audit prints `0` and the development audit prints a non-zero code, after both archives exited `0`.

## Report

Finish with:

- the pattern (Dual-Target or Single-Target), the development target or configuration, its bundle identifier, and the condition in use;
- every file changed, with one line on what each change does;
- the gate: both exit codes and the five check lines of the shipping audit;
- the Channel URL the development variant points at, and the next step for the project — publishing with `iosparkle publish`, specified in the iOSparkle Channel Specification (`docs/agent/channel-spec.md`).
