AppLovinPreProcessiOS.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. //
  2. // AppLovinBuildPreProcessiOS.cs
  3. // AppLovin MAX Unity Plugin
  4. //
  5. // Created by Jonathan Liu on 10/17/2023.
  6. // Copyright © 2023 AppLovin. All rights reserved.
  7. //
  8. #if UNITY_IOS
  9. using System.Xml.Linq;
  10. using UnityEditor.Build;
  11. using UnityEditor.Build.Reporting;
  12. namespace AppLovinMax.Scripts.IntegrationManager.Editor
  13. {
  14. public class AppLovinPreProcessiOS : AppLovinPreProcess, IPreprocessBuildWithReport
  15. {
  16. public void OnPreprocessBuild(BuildReport report)
  17. {
  18. AddGoogleCmpDependencyIfNeeded();
  19. }
  20. private const string ElementNameIosPods = "iosPods";
  21. private const string ElementNameIosPod = "iosPod";
  22. private const string AttributeNameName = "name";
  23. private const string AttributeNameVersion = "version";
  24. private const string UmpDependencyPod = "GoogleUserMessagingPlatform";
  25. private const string UmpDependencyVersion = "~> 2.1";
  26. private static void AddGoogleCmpDependencyIfNeeded()
  27. {
  28. if (AppLovinInternalSettings.Instance.ConsentFlowEnabled)
  29. {
  30. var umpDependency = new XElement(ElementNameIosPod,
  31. new XAttribute(AttributeNameName, UmpDependencyPod),
  32. new XAttribute(AttributeNameVersion, UmpDependencyVersion));
  33. var success = AddOrUpdateIosDependency(UmpDependencyPod, umpDependency);
  34. if (!success)
  35. {
  36. MaxSdkLogger.UserWarning("Google CMP will not function. Unable to add GoogleUserMessagingPlatform dependency.");
  37. }
  38. }
  39. else
  40. {
  41. RemoveIosDependency(UmpDependencyPod);
  42. }
  43. }
  44. /// <summary>
  45. /// Adds or updates an iOS pod in the AppLovin Dependencies.xml file.
  46. /// </summary>
  47. /// <param name="pod">The pod that we are trying to update</param>
  48. /// <param name="newDependency">The new dependency to add if it doesn't exist</param>
  49. /// <returns>Returns true if the file was successfully edited</returns>
  50. private static bool AddOrUpdateIosDependency(string pod, XElement newDependency)
  51. {
  52. var dependenciesFilePath = AppLovinDependenciesFilePath;
  53. var dependenciesDocument = GetAppLovinDependenciesFile(dependenciesFilePath, AppLovinIntegrationManager.IsPluginInPackageManager);
  54. if (dependenciesDocument == null) return false;
  55. AddOrUpdateDependency(dependenciesDocument,
  56. ElementNameIosPods,
  57. ElementNameIosPod,
  58. AttributeNameName,
  59. pod,
  60. newDependency);
  61. return SaveDependenciesFile(dependenciesDocument, dependenciesFilePath);
  62. }
  63. /// <summary>
  64. /// Removed an iOS pod from the AppLovin Dependencies.xml file.
  65. /// </summary>
  66. /// <param name="pod">The pod to remove</param>
  67. private static void RemoveIosDependency(string pod)
  68. {
  69. var dependenciesFilePath = AppLovinDependenciesFilePath;
  70. var dependenciesDocument = GetAppLovinDependenciesFile(dependenciesFilePath);
  71. if (dependenciesDocument == null) return;
  72. var removed = RemoveDependency(dependenciesDocument,
  73. ElementNameIosPods,
  74. ElementNameIosPod,
  75. AttributeNameName,
  76. pod);
  77. if (!removed) return;
  78. SaveDependenciesFile(dependenciesDocument, dependenciesFilePath);
  79. }
  80. public int callbackOrder
  81. {
  82. get { return CallbackOrder; }
  83. }
  84. }
  85. }
  86. #endif