Skip to content

Refactoring ios code signing documentation #2879

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 3 additions & 50 deletions content/partials/alternative-code-signing-methods-ios.md
Original file line number Diff line number Diff line change
@@ -1,57 +1,10 @@
---
---

### Automatic vs Manual code signing
## Alternative code signing
### Set up provisioning profiles and Certificates from environment variables

{{<notebox>}}
Signing iOS applications requires [Apple Developer Program](https://developer.apple.com/programs/enroll/) membership.
{{</notebox>}}

Signing iOS apps requires a `signing certificate` (App Store **development** or **distribution** certificate in `.p12` format) and a `provisioning profile`. In **manual code signing** you save these files as Codemagic `environment variables` and manually reference them in the appropriate build steps.

In **Automatic code signing**, Codemagic takes care of Certificate and Provisioning profile management for you. Based on the `Certificate private key` that you provide, Codemagic will automatically fetch the correct certificate from the App Store or create a new one if necessary.

### Automatic code signing

When automatic code signing is used, then most up-to-date signing files are obtained directly from Apple during the build time. This requires that Codemagic has access to your Apple Developer portal account, which is achieved by using App Store Connect API key.

#### Creating the App Store Connect API key

{{< include "/partials/app-store-connect-api-key.md" >}}

{{< include "/partials/code-signing-ios-obtain-certificate.md" >}}

{{< include "/partials/code-signing-ios-configure-environment-vars.md" >}}

Finally, to code sign the app, add the following commands in the [`scripts`](../getting-started/yaml#scripts) section of the configuration file, after all the dependencies are installed, right before the build commands.

{{< highlight yaml "style=paraiso-dark">}}
scripts:
- name: Set up keychain to be used for code signing using Codemagic CLI 'keychain' command
script: keychain initialize
- name: Fetch signing files
script: |
app-store-connect fetch-signing-files "$BUNDLE_ID" \
--type IOS_APP_STORE \
--create
- name: Set up signing certificate
script: keychain add-certificates
- name: Set up code signing settings on Xcode project
script: xcode-project use-profiles
{{< /highlight >}}

Instead of specifying the exact bundle-id, you can use `"$(xcode-project detect-bundle-id)"`.

Based on the specified bundle ID and [provisioning profile type](https://github.com/codemagic-ci-cd/cli-tools/blob/master/docs/app-store-connect/fetch-signing-files.md#--typeios_app_adhoc--ios_app_development--ios_app_inhouse--ios_app_store--mac_app_development--mac_app_direct--mac_app_store--mac_catalyst_app_development--mac_catalyst_app_direct--mac_catalyst_app_store--tvos_app_adhoc--tvos_app_development--tvos_app_inhouse--tvos_app_store) set with the `--type` argument, Codemagic will fetch or create the relevant provisioning profile and certificate to code sign the build.

If you are publishing to the **App Store** or you are using **TestFlight** to distribute your app to test users, set the `--type` argument to `IOS_APP_STORE`.

When using a **third party app distribution service** such as Firebase App Distribution, set the `--type` argument to `IOS_APP_ADHOC`


### Manual code signing

In order to use manual code signing, you need the following:
In order to use this alternative code signing, you need the following:
- **Signing certificate**: Your development or distribution certificate in .P12 format.
- **Certificate password**: The certificate password if the certificate is password-protected.
- **Provisioning profile**: You can get it from **Apple Developer Center > Certificates, Identifiers & Profiles > Profiles** and select the provisioning profile you would like to export and download.
Expand Down
52 changes: 52 additions & 0 deletions content/yaml-code-signing/signing-ios-automatic.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
---
title: Signing iOS apps automatically
description: How to set up iOS code signing in using automatic code signing in codemagic.yaml
weight: 1
aliases: [../code-signing-yaml/signing, /code-signing-yaml/signing-ios, code-signing-identities, ../yaml-code-signing/code-signing-identities]
---

All iOS applications have to be digitally signed before they can be installed on real devices or made available to the public.

### Automatic code signing

In **Automatic code signing**, Codemagic takes care of Certificate and Provisioning profile management for you. Based on the `Certificate private key` that you provide, Codemagic will automatically fetch the correct certificate from the App Store or create a new one if necessary.

When automatic code signing is used, then most up-to-date signing files are obtained directly from Apple during the build time. This requires that Codemagic has access to your Apple Developer portal account, which is achieved by using App Store Connect API key.

{{<notebox>}}
Signing iOS applications requires [Apple Developer Program](https://developer.apple.com/programs/enroll/) membership.
{{</notebox>}}


#### Creating the App Store Connect API key

{{< include "/partials/app-store-connect-api-key.md" >}}

{{< include "/partials/code-signing-ios-obtain-certificate.md" >}}

{{< include "/partials/code-signing-ios-configure-environment-vars.md" >}}

Finally, to code sign the app, add the following commands in the [`scripts`](../getting-started/yaml#scripts) section of the configuration file, after all the dependencies are installed, right before the build commands.

{{< highlight yaml "style=paraiso-dark">}}
scripts:
- name: Set up keychain to be used for code signing using Codemagic CLI 'keychain' command
script: keychain initialize
- name: Fetch signing files
script: |
app-store-connect fetch-signing-files "$BUNDLE_ID" \
--type IOS_APP_STORE \
--create
- name: Set up signing certificate
script: keychain add-certificates
- name: Set up code signing settings on Xcode project
script: xcode-project use-profiles
{{< /highlight >}}

Instead of specifying the exact bundle-id, you can use `"$(xcode-project detect-bundle-id)"`.

Based on the specified bundle ID and [provisioning profile type](https://github.com/codemagic-ci-cd/cli-tools/blob/master/docs/app-store-connect/fetch-signing-files.md#--typeios_app_adhoc--ios_app_development--ios_app_inhouse--ios_app_store--mac_app_development--mac_app_direct--mac_app_store--mac_catalyst_app_development--mac_catalyst_app_direct--mac_catalyst_app_store--tvos_app_adhoc--tvos_app_development--tvos_app_inhouse--tvos_app_store) set with the `--type` argument, Codemagic will fetch or create the relevant provisioning profile and certificate to code sign the build.

If you are publishing to the **App Store** or you are using **TestFlight** to distribute your app to test users, set the `--type` argument to `IOS_APP_STORE`.

When using a **third party app distribution service** such as Firebase App Distribution, set the `--type` argument to `IOS_APP_ADHOC`
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Signing iOS apps
description: How to set up iOS code signing in codemagic.yaml
title: Signing iOS apps manually
description: How to set up manuall iOS code signing in codemagic.yaml
weight: 1
aliases: [../code-signing-yaml/signing, /code-signing-yaml/signing-ios, code-signing-identities, ../yaml-code-signing/code-signing-identities]
---
Expand Down Expand Up @@ -39,7 +39,7 @@ Signing iOS applications requires [Apple Developer Program](https://developer.ap
### Adding the provisioning profile
{{< include "/partials/quickstart/code-signing-ios-add-provisioning-profile.md" >}}

## Referencing certificates and profiles in codemagic.yaml
### Referencing certificates and profiles in codemagic.yaml

Codemagic provides two means of fetching the required certificates and provisioning profiles during the build with the use of `codemagic.yaml`. Fetching can either be configured by specifying the distribution type and bundle identifier, or for more advanced use-cases, individual files can be fetched by their reference names.

Expand Down Expand Up @@ -121,7 +121,7 @@ workflows:
{{< /highlight >}}


## Using provisioning profiles
### Using provisioning profiles

To apply the profiles to your project during the build, add the following script before your build scripts:

Expand Down