# Setup iOS Project for Fastlane

Source: https://help.testapp.io/setup-ios-project-for-fastlane/

This guide walks you through setting up an iOS project with Fastlane for code signing and uploading builds to [TestApp.io](https://testapp.io/) for testing and distribution.

> **Plugin v2.x requires Ruby 3.0+.** If your CI image still uses Ruby 2.6 or 2.7, pin to `~> 1.0` in your Pluginfile until you upgrade Ruby. See [Compatibility](https://help.testapp.io/fastlane-plugin/#compatibility) for details.

## 1. Install Fastlane

Create a `./Gemfile` in the root directory of your project:

```ruby
source "https://rubygems.org"

gem "fastlane"
```

Then run:

```bash
bundle install
```

Add both `./Gemfile` and `./Gemfile.lock` to version control. For more details, see [Fastlane Setup Guide](https://docs.fastlane.tools/getting-started/ios/setup/).

## 2. Initialize Fastlane

In your iOS project folder, run:

```bash
bundle exec fastlane init
```

Follow the wizard, it will create `./fastlane/Appfile` with your Apple ID and team configuration.

## 3. Initialize Match

Fastlane **match** generates all necessary certificates and provisioning profiles and stores them encrypted in a Git repository.

First, create a **private empty GitHub repository** for storing certificates and provisioning profiles. Then run:

```bash
bundle exec fastlane match init
```

Follow the prompts and provide the new empty Git repository URL when asked. This creates the `Matchfile`.

## 4. Generate Certificates and Provisioning Profiles

```bash
bundle exec fastlane match development
# Or for ad-hoc distribution:
bundle exec fastlane match adhoc
```

Follow the prompts. Fastlane will generate certificates and profiles and store them encrypted in the Git repository.

> **Note:** You will be asked to provide a match password used for encrypting the certificates and profiles. Store this password securely.

## 5. Select Provisioning Profiles in Xcode

The newly created certificates and profiles should now be available in your project. Open Xcode and go to **Signing & Capabilities**.

![Select certificate in Xcode](https://f000.backblazeb2.com/file/help-testappio/2022/03/select-cert_o.jpg)

> ⚠️ ****Important:**** Do not choose ****Automatically manage signing****. Select your provisioning profiles manually.

## 6. Add TestApp.io Fastlane Plugin

Install the TestApp.io plugin for Fastlane:

```bash
bundle exec fastlane add_plugin testappio
```

## 7. Upload Builds to TestApp.io

Add the `upload_to_testappio` action to your Fastfile:

```ruby
# fastlane/Fastfile
default_platform :ios

platform :ios do
  desc "Build ad-hoc and upload to TestApp.io"
  lane :beta do
    match(type: "adhoc")
    gym(export_method: "ad-hoc")
    upload_to_testappio(
      api_token: ENV["TESTAPPIO_API_TOKEN"],
      app_id:    ENV["TESTAPPIO_APP_ID"],
      release_notes: "New beta build",
      git_release_notes: true,
      git_commit_id: false,
      notify: true,
      self_update: true
    )
  end
end
```

Set these environment variables (or pass them directly):

- `TESTAPPIO_API_TOKEN`. Get from [Profile → Tokens](https://portal.testapp.io/profile/tokens)
- `TESTAPPIO_APP_ID`. Get from your [app page](https://portal.testapp.io/apps) under Integrations → Releases

For more details, see [Fastlane Plugin Guide](https://help.testapp.io/fastlane-plugin/).

---

#### Related Articles

- [ta-cli Documentation](https://help.testapp.io/ta-cli/)

> **Tip:** Once your CI/CD pipeline uploads a build, team members using the [TestApp.io mobile app](https://help.testapp.io/mobile-app-getting-started/) receive a push notification and can install the build with a single tap. You can also create [share links](https://help.testapp.io/how-to-share/) to distribute builds to external testers and clients.

---

Need help? [Contact us](https://testapp.io/contact-us) or visit [help.testapp.io](https://help.testapp.io/).
