Bez popisu
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

AppleAuthMacosPostprocessorHelper.cs 2.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using System;
  2. using System.IO;
  3. using System.Text.RegularExpressions;
  4. using UnityEditor;
  5. using UnityEngine;
  6. namespace AppleAuth.Editor
  7. {
  8. public static class AppleAuthMacosPostprocessorHelper
  9. {
  10. /// <summary>
  11. /// Use this script to change the bundle identifier of the plugin's library bundle to replace it with a personalized one for your product.
  12. /// This should avoid CFBundleIdentifier Collision errors when uploading the app to the macOS App Store
  13. /// </summary>
  14. /// <remarks>Basically this should replace the plugin's bundle identifier from "com.lupidan.MacOSAppleAuthManager" to "{your.project.application.identifier}.MacOSAppleAuthManager"</remarks>
  15. /// <param name="target">The current build target, so it's only executed when building for MacOS</param>
  16. /// <param name="path">The path of the built .app file</param>
  17. public static void FixManagerBundleIdentifier(BuildTarget target, string path)
  18. {
  19. if (target != BuildTarget.StandaloneOSX)
  20. {
  21. Debug.LogError("AppleAuthMacosPostprocessorHelper: FixManagerBundleIdentifier should only be called when building for macOS");
  22. return;
  23. }
  24. const string bundleIdentifierPattern = @"(\<key\>CFBundleIdentifier\<\/key\>\s*\<string\>)(com\.lupidan)(\.MacOSAppleAuthManager\<\/string\>)";
  25. const string macOSAppleAuthManagerInfoPlistRelativePath = "/Contents/Plugins/MacOSAppleAuthManager.bundle/Contents/Info.plist";
  26. try
  27. {
  28. var macosAppleAuthManagerInfoPlistPath = path + macOSAppleAuthManagerInfoPlistRelativePath;
  29. var macosAppleAuthManagerInfoPlist = File.ReadAllText(macosAppleAuthManagerInfoPlistPath);
  30. var modifiedMacosAppleAuthManagerInfoPlist = Regex.Replace(
  31. macosAppleAuthManagerInfoPlist,
  32. bundleIdentifierPattern,
  33. "$1" + PlayerSettings.applicationIdentifier + "$3");
  34. File.WriteAllText(macosAppleAuthManagerInfoPlistPath, modifiedMacosAppleAuthManagerInfoPlist);
  35. Debug.Log("AppleAuthMacosPostprocessorHelper: Renamed MacOSAppleAuthManager.bundle bundle identifier from \"com.lupidan.MacOSAppleAuthManager\" -> \"" + PlayerSettings.applicationIdentifier + ".MacOSAppleAuthManager\"");
  36. }
  37. catch (Exception exception)
  38. {
  39. Debug.LogError("AppleAuthMacosPostprocessorHelper: Error while fixing MacOSAppleAuthManager.bundle bundle identifier :: " + exception.Message);
  40. }
  41. }
  42. }
  43. }