---
title: "Notarization and distribution"
description: "Local, development and Developer ID builds, notarized and stapled, with SwiftPM or Xcode."
---

```sh
xcrun notarytool store-credentials notary
swift package --allow-writing-to-package-directory --allow-network-connections all \
    cef bundle --product MyApp --sign "Developer ID Application: Example Corp (A1B2C3D4E5)" \
    --notarize --keychain-profile notary
```

## Distribution

### Local builds (ad hoc)

- [ ] `swift package … cef bundle --product MyApp`. With no identity in the
  keychain, the bundle is signed ad hoc, without the hardened runtime.
- [ ] Runs on the Mac that built it. Gatekeeper refuses it on another Mac.
- [ ] `.automatic` safe storage uses a mock keychain; Chromium passkeys
  offer security keys and, with the `bluetooth` capability, phones.
- [ ] To test the hardened runtime and the entitlements locally, bundle with
  `--hardened-runtime`; unrestricted entitlements apply ad hoc.

### Development builds (Apple Development)

- [ ] An Apple Development certificate in the login keychain (Xcode,
  Settings > Accounts > Manage Certificates). `cef bundle` picks it up
  without `--sign`.
- [ ] For restricted entitlements, a macOS App Development profile that
  lists this Mac, set as `provisioningProfile`.
- [ ] The hardened runtime is on and `get-task-allow` lets a debugger
  attach. The app runs on the Mac that built it and on the devices the
  profile lists; Gatekeeper refuses it when downloaded.
- [ ] `.automatic` safe storage uses the login keychain: macOS asks once for
  "<bundle identifier> Safe Storage", and Always Allow lasts across rebuilds.

### Distribution builds (Developer ID, notarized)

- [ ] A Developer ID Application certificate (only the team's Account
  Holder can create one).
- [ ] A Developer ID provisioning profile when the app claims restricted
  entitlements (for iCloud Keychain passkeys).
- [ ] Store notary credentials once:
  `xcrun notarytool store-credentials notary` (an app-specific password, or
  an App Store Connect API key).
- [ ] Bundle, notarize and staple:

  ```sh
  swift package --allow-writing-to-package-directory --allow-network-connections all \
      cef bundle --product MyApp --sign "Developer ID Application: Example Corp (A1B2C3D4E5)" \
      --notarize --keychain-profile notary
  ```

  This signs with the hardened runtime and a secure timestamp, zips the app
  with `ditto`, submits it with `xcrun notarytool submit --wait`, prints the
  notary log when Apple rejects it, staples the ticket to the app with
  `xcrun stapler staple`, and zips the stapled app again (a zip cannot carry
  a ticket of its own). With `--package dmg` it wraps the app in a disk
  image signed with the same identity and staples the disk image instead;
  see [SwiftPM's plugin sandbox](/ship/notarization#swiftpms-plugin-sandbox) for where that
  runs. This path follows Apple's notarization documentation and has not
  been run against Apple's service.
- [ ] `swift package … cef doctor dist/MyApp.app` reports no errors, and
  `spctl --assess --type execute -vv dist/MyApp.app` prints
  `source=Notarized Developer ID`.
- [ ] For Widevine, with `"protectedMedia"` in `capabilities`: the
  Browser example's `browser://playground/widevine.html` plays and says
  "Playing with com.widevine.alpha". (Not yet run with a team signature.)

### With Xcode

Signing with a team, archiving and exporting are Xcode's, as for any app;
the build phase signs the parts inside with the archive's identity. Not
yet run with a team signature or against Apple's notary service:

- [ ] Choose the team in Signing & Capabilities; remove
  `RUNTIME_EXCEPTION_DISABLE_LIBRARY_VALIDATION` if the target has it.
- [ ] Product › Archive (`xcodebuild archive -scheme MyApp -archivePath
  MyApp.xcarchive`).
- [ ] Organizer › Distribute App › Direct Distribution, which exports with
  the Developer ID identity, notarizes and staples; or
  `xcodebuild -exportArchive -archivePath MyApp.xcarchive -exportPath out
  -exportOptionsPlist options.plist` with `method` `developer-id`, then
  `swift package … cef notarize out/MyApp.app --keychain-profile notary`
  (or `xcrun notarytool submit` and `xcrun stapler staple` yourself).
  Xcode's export signs the app again with the Developer ID identity and a
  secure timestamp, nested code first; whether it re-signs the helper apps
  in `Contents/Frameworks` itself is unverified, so check the result.
- [ ] `cefswift doctor out/MyApp.app` (the tool the phase built, in
  `$(OBJROOT)/CefSwift`) or `swift package … cef doctor` from a package
  reports no errors, and `spctl --assess --type execute -vv out/MyApp.app`
  prints `source=Notarized Developer ID`.

Without a team, `Examples/Xcode/ExportOptions.plist` (`method`
`mac-application`) exports the archived app as it is signed, ad hoc; it
runs on the Mac that built it. Mac App Store distribution is not possible:
see [App Sandbox](/ship/sandbox#app-sandbox).

### SwiftPM's plugin sandbox

`swift package` runs the plugin in a sandbox. Inside it:

- `codesign` and `security` see the keychains of the search list (the
  login keychain), not other keychain files: `--keychain` with a file
  outside the search list fails with "no identity found".
- `hdiutil` cannot create disk images, so `--format dmg` fails; `zip` works.
- `spctl` cannot assess apps (see [cef doctor](/ship/bundling#cef-doctor)).
- Whether `notarytool` reaches its keychain profile and Apple's service from
  inside the sandbox has not been tested.

Where a step fails for this reason, the plugin's message says so; run the
command it prints in Terminal, or pass `--disable-sandbox` to
`swift package`, which turns the sandbox off for the whole run.
