Last active
October 17, 2023 02:59
-
-
Save camnewnham/3266c547ed733ceb99df3f379e289509 to your computer and use it in GitHub Desktop.
Run Unity iOS app behind control center
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Belongs in an Assets/**/Editor folder | |
public class iOSPostProcessor | |
{ | |
/// <summary> | |
/// Post processor to automate skipping the checkbox on testflight for encryption compliance. | |
/// </summary> | |
[PostProcessBuild(-999)] | |
public static void OnPostProcessBuildRunInBackground(BuildTarget buildTarget, string path) | |
{ | |
if (buildTarget != BuildTarget.iOS) | |
{ | |
return; | |
} | |
string filePath = Path.Combine(path, "Classes", "UnityAppController.mm"); | |
string content = File.ReadAllText(filePath); | |
// Check if this mod has already been applied -> if we have "append" the build. | |
Regex regex = new Regex("applicationDidEnterBackground\\(\\).+?}", RegexOptions.Singleline); | |
Match match = regex.Match(content); | |
if (!match.Success) | |
{ | |
Debug.LogError("Failed to parse UnityAppController.mm"); | |
return; | |
} | |
int numberOfLinesInMethod = match.Value.Split("\n").Length; | |
if (numberOfLinesInMethod > 6) | |
{ | |
Debug.Log("Skipped modification to UnityAppController.mm as applicationDidEnterBackground() had more content than expected."); | |
return; | |
} | |
content = content | |
.Replace("applicationWillResignActive", "###temp###") | |
.Replace("applicationDidEnterBackground", "applicationWillResignActive") | |
.Replace("###temp###", "applicationDidEnterBackground"); | |
File.WriteAllText(filePath, content); | |
Debug.Log("Moved iOS pause functionality from applicationWillResignActive to applicationDidEnterBackground."); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment