To add iOS capabilities in Unity Build Automation, use a PostProcessBuildAttribute or post-export method in Assets/Editor that edits the Xcode project with PBXProject and ProjectCapabilityManager before Xcode signs it. Wrap ProjectCapabilityManager calls in try-catch, and enable the same capabilities for your App ID and the provisioning profile uploaded to Build Automation.
Symptoms
I want to add custom capabilities (for example Push Notifications, Sign in with Apple, or Associated Domains) to the Xcode project that Unity Build Automation generates for my iOS build.
Cause
Unity Build Automation exports the Xcode project and builds it in the same job, so you can't open the project in Xcode to add capabilities manually. You need to add them from a script that runs after Unity exports the Xcode project and before Xcode builds and signs it.
Resolution
Use one of the following hooks, together with the Xcode manipulation API (PBXProject) and ProjectCapabilityManager:
- A method tagged with PostProcessBuildAttribute. It runs both locally and in Build Automation.
- A Post-export method configured in the build configuration's Advanced settings. It runs only in Build Automation and receives the path to the exported Xcode project.
Place the script in an Assets/Editor folder. As a best practice, wrap the ProjectCapabilityManager calls in a try-catch block, since they might throw exceptions when called multiple times.
Important: the capabilities you add must also be enabled for your App ID in the Apple Developer portal and included in the provisioning profile uploaded to Build Automation. Otherwise, the build fails during code signing.