Integrate Fastlane to iOS project: Lesson 3

Explanation of Fastlane lane and action, download cert and provisioning profile from Apple account by using action

Mark
3 min readAug 31, 2018

In lesson 2, we initialled Fastlane to our iOS project and use lane to print hello world. This time, we will explain what is Fastlane action.

What is action?

action is a library provided by Fastlane. It helps you to perform different actions, like send message to Slack, upload the build to TestFlight.

You can type fastlane actions to see the available actions.

Output of fastlane actions

We use get_certificates as an example to explain.

Fastlane has a service called match to handle the certificates and provisioning profile, and we will discuss that later.

Example: get_certificates

get_certificates is an action which helps to download the iOS development/product certificates from Apple Developer Account to your local Mac. It helps you to use the correct certificates when you want to archive your app and without troubles.

Type fastlane action get_certificates in Terminal. (you can type fastlane action other_action to check other actions)

It shows 2 parts, explanation of what get_certificates is and what parameters you need to pass to this action.

Output of fastlane aciton get_certificates

Open your Fastfile and copy the following code. (assume you have already created a production certificates in your developer account)

// get the production certificates from Apple Developer
lane :get_production_cert_from_apple do
get_certificates(
development:false,
force:false,
username: <your_apple_id>,
team_name: <your_team_name>,
filename: <cert_file_name>,
output_path: <cert_output_path>
)
end

development: false - use production certificates

force: false - use the existing certificates

username - your Apple ID, login to Apple

team_name - skip that if you only have 1 team

filename - usually skip that, use the originally name

output_path - the output path, suggest to named as fastlane_result/<env_name>/<xcode_project_config>, e.g. fastlane_result/dev/Release

Run bundle exec fastlane ios get_production_cert_from_apple, the cert will be saved in your output_path location. Mac may ask you the permission to access Keychain, you just need to click always allow is ok.

Example: get_provisioning_profile

After get the production certificates, we need to get the correct provisioning profile in order to build the app, and we will use get_provisioning_profile to do that.

Copy the following code to the fastfile

lane :build_app do
// get the production certificates from Apple Developer
get_certificates(
development:false,
force:false,
username: <your_apple_id>,
team_name: <your_team_name>,
filename: <cert_file_name>,
output_path: <cert_output_path>
)

// get the production certificates from Apple Developer
get_provisioning_profile(
adhoc: true,
app_identifier: <your_app_id>,
username: <your_apple_id>,
output_path: <cert_output_path>
)
// build the app (please check lesson 4)
end

Now, you can run bundle exec fastlane ios build_app to get the cert and provisioning profile into your Mac.

You can use fastlane action get_provisioning_profile to check more detail.

What’s next?

Next lesson, we will use build_app action to build the app from Xcode project and try to upload the build to Crashlytics and Hockey App.

--

--