Research / Design / Consulting

This is useful when you want to edit the Info.plist of an Xcode project built by Unity when building for iOS. This can be used for example to change the values of Version (CFBundleShortVersionString) and Build (CFBundleVersion) in an Xcode project from within Unity, as a build post-process.

Step-by-step guide

  1. Create/Have a Unity project
  2. Create a folder inside Assets called Editor
  3. Download the Xcode Manipulation API files from https://bitbucket.org/Unity-Technologies/xcodeapi/src/ and place them inside a sub-folder inside Assets > Editor such as Assets > Editor > xcodeapi
  4. You can now create a script such as the one below to alter CFBundleVersion in Xcode plist

using UnityEngine;
using UnityEditor;
using UnityEditor.Callbacks;
using System.Collections;
using UnityEditor.iOS.Xcode;
using System.IO;

public class ChangeIOSBuildNumber {

[PostProcessBuild]
public static void ChangeXcodePlist(BuildTarget buildTarget, string pathToBuiltProject) {

    if (buildTarget == BuildTarget.iOS) {
   
        // Get plist
        string plistPath = pathToBuiltProject + "/Info.plist";
        PlistDocument plist = new PlistDocument();
        plist.ReadFromString(File.ReadAllText(plistPath));
   
        // Get root
        PlistElementDict rootDict = plist.root;
   
        // Change value of CFBundleVersion in Xcode plist
        var buildKey = "CFBundleVersion";
        rootDict.SetString(buildKey,"2.3.4");
   
        // Write to file
        File.WriteAllText(plistPath, plist.WriteToString());
    }
}

}

Which sets the CFBundleVersion in your Info.plist in a post process step to "2.3.4" (works also in Unity Cloud Build in all Tiers).