Building for iOS
Build Automation helps you automate the process of building your Unity Project for iOS devices. There are a number of prequisites for iOS development. Note that Apple processes and requirements do change over time, so it's best to refer to the Apple developer website should you encounter issues.
A Note on the Apple Privacy Manifest
Apple is introducing a privacy policy for including privacy manifest files in new and updated applications targeted for iOS, iPadOS, tvOS, and visionOS platforms on the App Store.
The privacy manifest file PrivacyInfo.xcprivacy
lists the types of data your Unity applications collect (or any third-party SDKs, packages, and plug-ins), and the reasons for using certain Required Reason API categories. Apple also requires that certain domains be declared as "tracking" and they may be blocked unless a user provides consent.
Important: If the use of the Required Reasons APIs by you or third-party SDKs isn’t declared in the privacy manifest, your application might be rejected by the App Store. For more information, visit Apple’s documentation on Required Reasons APIs.
Unity Build Automation does not collect data or engage in any data practices requiring disclosure in a privacy manifest file.
Joining the Apple Developer Program
To develop iOS apps you must be a member of the Apple Developer Program. This lets you build, test, and eventually release your apps to the Apple App Store.
Provisioning profiles
A provisioning profile ties developers and devices to an authorized Development Team and enables you to use a device for testing. You must install a Development Provisioning Profile on each device you plan to use to run your app.
Each Development Provisioning Profile contains a set of Development Certificates, Unique Device Identifiers (UDID), and an App ID.
To use a device for testing, you must also include your Development Certificate in the profile. A single device can contain multiple provisioning profiles.
Components of a provisioning profile
Certificates determine whether your app is development-only or a release candidate for the App Store.
Identifiers are the unique IDs that identify your project. For basic projects, or if this is your first iOS project, you should make an App ID. This is often the same as your Unity Project’s Bundle ID.
Tip: For more information on signing identities and certificates, see Maintain signing assets on the Apple developer website.
Devices are the hardware—such as an iPhone, iPad, or iPod—on which you plan to test your project. You must retrieve the UDID for each device on which you plan to test your game, even if you are using a virtual device or simulator.
You will then add the UDID to the Devices section in the Apple developer portal.
Creating an iOS certificate and p12 file
When you create a certificate, you must decide whether to create a Development Certificate (used only for testing), or a Distribution Certificate, which you can use for testing or to distribute your app via the App Store.
Creating a certificate
- Sign in to the Apple Developer Program.
- Navigate to Account > Certificates.
- Click the add button (+) next to Certificates to add a new certificate.
- Choose the type of certificate to generate.
- Use the Keychain Access program on your Mac to generate a Certificate Signing Request (CSR) file.
- Back on the Create a New Certificate page, upload your CSR file (which might have the extension .certSigningRequest).
- To download your certificate to your Mac, click the Download button on the Your Certificate is Ready screen. Store this file somewhere safe and back it up.
- To add the certificate to a keychain, locate the certificate file and double-click it. This opens the Keychain Access program. If you get a popup with the message “Do you want to add the certificate to a keychain?”, choose login and click the Add button.
Creating a p12 file
To create apps using Build Automation, you must convert your certificate file to a p12 file. A p12 file is a file that contains your private key and certificate and is used to sign your code.
- Open the Keychain Access program on your Mac.
- In the left-hand column, under Keychains, verify that Login is selected.
- In the left-hand column, under Category, verify that My Certificates is selected. In the main Keychain Access pane, select your certificate. Note: Typically, your certificate is located under My Certificates. If it is not there, check under Certificates.
- From the File menu, select File > Export Items, or right-click and select Export.
- Select Personal Information Exchange (.p12) from the File Format drop-down menu. Note: If Login under Keychains and My Certificates under Category is not selected, the p12 option is greyed out.
- Ceate a password for the p12 file. You will need this password when adding Credentials to your Build Target in Unity Build Automation, so keep a note of it.
Adding devices
For development purposes, Apple requires the UDID of each device on which you intend to install your app. Once your app is accepted into the App Store, anyone can download and install it; provided they have the correct version of iOS and meet any other requirements.
Finding your UDID
You can use iTunes to retrieve the UDID of your device. For a walkthrough of the retrieval process, see here.
Add the UDID in the Apple developer portal
- Sign in to the Apple Developer Program.
- Navigate to Account > Devices.
- Click the add button (+) next to Devices to add a new device.
- Give the device a name you will recognize, and enter your UDID into the UDID field.
- Click Continue.
- Review the registration information, then click Register.
Create App ID
- Sign in to the Apple Developer Program.
- Navigate to Account > Identifiers.
- Click the add button (+) next to Identifiers to add a new Identifier.
- For Description enter the name of your App, without any special characters.
- Select Explicit or Wildcard App ID. If you intend to incorporate specific services such as Game Center or In-App Purchases, create an Explicit ID. If you don’t need these services, then a Wildcard App ID can be created and re-used for multiple projects.
- Select the corresponding checkboxes to enable the app capabilities you want to use.
- Click Continue.
- Review the registration information, then click Register.
Create a development provisioning profile
- Sign in to the Apple Developer Program.
- Navigate to Account > Profiles.
- Click the add button (+) next to Profiles to add a new Profile.
- Under Development, select the type of provisioning profile you want to create, then click Continue.
- Select the App ID to use for development, and click the Continue button.
- Select one or more certificates, and click the Continue button.
- Select one or more devices, then click Continue.
- Enter a profile name, then click Generate.
- Click Download.
Configuring your app to build for iOS
You should now be able to configure an iOS target in Build Automation using the following items:
- Your provisioning profile (.mobileprovision)
- Your .p12 file
- The password for your .p12 file
Xcode frameworks
If your iOS Project requires additional Xcode frameworks, use the PBXProject API to add those frameworks to the Xcode Project files created by Unity Build Automation.
For an example of a Unity Project that uses the API, see the UpdateXcodeProject example Project on GitHub. You can use the example to experiment and to learn from.
One of the plugins of the example Project is an external Xcode project manipulation DLL. The DLL is the build product of the source available in Unity’s Bitbucket repository. A preferred way to include Xcode project manipulation functionality is to copy the C# source code files to the Assets/Editor folder in your Project.
There are two ways to call this API to manipulate the Xcode project:
- Use the built-in Unity PostProcessBuildAttribute, which is executed before the Unity Build Automation Post-Export method runs.
- Use the Unity Build Automation post-export method (requires access to advanced settings).