Skip to content

Native iOS (Swift / Xcode)

Native iOS automation manages code signing certificates and provisioning profiles via match, archives binaries with gym (build_app), runs unit tests with scan (run_tests), and uploads to TestFlight/App Store via pilot and deliver.

flowchart LR
    Sync["match (Sync Certificates & Profiles)"] --> Test["run_tests (scan: xcodebuild test)"]
    Test --> Build["build_app (gym: archive & export IPA)"]
    Build --> TestFlight["upload_to_testflight (pilot)"]
    TestFlight --> AppStore["upload_to_app_store (deliver)"]

Directory Setup

Initialize Fastlane inside your iOS project root or ios/ folder:

Terminal window
cd ios
bundle exec fastlane init

Recommended structure:

my-ios-app/
├── App.xcodeproj
├── App.xcworkspace
├── Podfile (optional)
├── fastlane/
│ ├── Appfile # app_identifier & apple_id
│ ├── Matchfile # git repo for certificates
│ └── Fastfile # iOS lanes
├── Gemfile
└── Gemfile.lock

Configuring Appfile & Matchfile

# fastlane/Appfile
app_identifier("com.example.myapp")
apple_id("developer@example.com")
team_id("A1B2C3D4E5")
itc_team_id("123456789")
# fastlane/Matchfile
git_url("git@github.com:my-org/ios-certificates.git")
storage_mode("git")
type("appstore")
app_identifier(["com.example.myapp"])

[!TIP] Dynamic Bundle IDs & Apple Capabilities: If your project requires dynamically configuring Apple capabilities (Sign in with Apple, Push Notifications, App Groups, Universal Links) across multi-tenant flavors or app extensions, automate them via Spaceship without manual portal clicks. See Programmatic Capabilities & Bundle IDs (Spaceship).


1. Single-App Pipeline: Test, Archive & TestFlight

# fastlane/Fastfile
default_platform(:ios)
platform :ios do
before_all do
# Authenticate with App Store Connect API Key (.p8)
app_store_connect_api_key(
key_id: ENV["ASC_KEY_ID"],
issuer_id: ENV["ASC_ISSUER_ID"],
key_content: ENV["ASC_KEY_CONTENT"],
is_key_content_base64: true
)
end
desc "Run unit and UI tests"
lane :test do
run_tests(
workspace: "App.xcworkspace",
scheme: "App",
devices: ["iPhone 15 Pro"]
)
end
desc "Archive and upload build to TestFlight"
lane :beta do
# 1. Sync App Store provisioning profiles in readonly mode
match(type: "appstore", readonly: is_ci)
# 2. Automatically bump build number from latest TestFlight build
increment_build_number(
build_number: latest_testflight_build_number + 1
)
# 3. Compile and export IPA
build_app(
workspace: "App.xcworkspace",
scheme: "App",
export_method: "app-store"
)
# 4. Upload to TestFlight
upload_to_testflight(
skip_waiting_for_build_processing: true
)
end
end

2. Managing Xcode Schemes & Configurations

If your Xcode project uses multiple build configurations (Debug, Staging, Release) or custom Schemes:

lane :build_scheme do |options|
scheme = options[:scheme] || "App-Staging"
configuration = options[:configuration] || "Staging"
match(type: "adhoc", readonly: true)
build_app(
workspace: "App.xcworkspace",
scheme: scheme,
configuration: configuration,
export_method: "ad-hoc"
)
end

Essential Native iOS Actions

Action Purpose Primary Options
match Sync certificates and provisioning profiles via encrypted Git type, readonly, app_identifier
build_app Archives and exports .ipa using xcodebuild (gym) workspace, scheme, export_method
run_tests Runs unit/UI tests and parses test results (scan) workspace, scheme, devices
upload_to_testflight Distributes builds to TestFlight beta groups (pilot) skip_waiting_for_build_processing, changelog
upload_to_app_store Submits binary and store listings for App Store review (deliver) submit_for_review, force, metadata_path