Skip to content

Instantly share code, notes, and snippets.

@osmanzeki
Forked from TiborUdvari/IncrementBuildNumber.cs
Created December 21, 2020 18:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save osmanzeki/f1daf0ea22c5894d37c2ed8eda379e2d to your computer and use it in GitHub Desktop.
Save osmanzeki/f1daf0ea22c5894d37c2ed8eda379e2d 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