iOS' capability setting can be modified by Unity Editor script.
I'm using Jenkins build machine. And sometimes the xcode project's capability settings modified. So, I need to add below script to add capabilities automatically.
The following script let you add capabilities for what you want to use. See also apple developer document to see what kind of capability you can use.
using UnityEditor;
using UnityEditor.Callbacks;
using UnityEditor.iOS.Xcode;
public class XCodePostProcessBuild
{
[PostProcessBuild]
public static void OnPostProcessBuild(BuildTarget buildTarget, string pathToBuiltProject)
{
if (buildTarget != BuildTarget.iOS) return;
string projPath = pathToBuiltProject + "/Unity-iPhone.xcodeproj/project.pbxproj";
ProjectCapabilityManager projCapability = new ProjectCapabilityManager(projPath, "Unity-iPhone/(entitlement file)", "Unity-iPhone");
projCapability.AddBackgroundModes(BackgroundModes.RemoteNotifications);
projCapability.AddPushNotifications(false);
projCapability.AddiCloud(true, true, null);
projCapability.WriteToFile();
}
}
The
entitlement file
is located in[your xcode project built]/Unity-iPhone/
, and the file's name ends with .entitlements.
PostProcessBuild
attribute let a method to get a notification just after building the player. It has an option to provide an order index in the callback, start from 0.