Skip to content

Instantly share code, notes, and snippets.

@TiborUdvari
Last active August 9, 2023 22:13
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save TiborUdvari/401e9053f64d5218ccd6d5b6412535d9 to your computer and use it in GitHub Desktop.
Save TiborUdvari/401e9053f64d5218ccd6d5b6412535d9 to your computer and use it in GitHub Desktop.
Unity Editor Script that increments build number for iOS builds
using UnityEngine;
using UnityEditor.Build;
using UnityEditor.Build.Reporting;
using UnityEditor;
public class IncrementBuildNumber : IPreprocessBuildWithReport
{
public int callbackOrder { get { return 0; } } // Part of the IPreprocessBuildWithReport interface
public void OnPreprocessBuild(BuildReport report)
{
if (report.summary.platform == BuildTarget.iOS) // Check if the build is for iOS
{
// Increment build number if proper int, ignore otherwise
int currentBuildNumber;
if (int.TryParse(PlayerSettings.iOS.buildNumber, out currentBuildNumber))
{
string newBuildNumber = (currentBuildNumber + 1).ToString();
Debug.Log("Setting new iOS build number to " + newBuildNumber);
PlayerSettings.iOS.buildNumber = newBuildNumber;
}
else
{
Debug.LogError("Failed to parse build number " + PlayerSettings.iOS.buildNumber + " as int.");
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment