TapDBIOSProcessor.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using System.Collections.Generic;
  2. using System.IO;
  3. using TapTap.Common.Editor;
  4. using UnityEditor;
  5. using UnityEditor.Callbacks;
  6. using UnityEngine;
  7. namespace TapTap.TapDB.Editor
  8. {
  9. #if UNITY_IOS
  10. public class TapDBIOSProcessor
  11. {
  12. [PostProcessBuild(104)]
  13. public static void OnPostprocessBuild(BuildTarget buildTarget, string path)
  14. {
  15. if (buildTarget != BuildTarget.iOS) return;
  16. var projPath = TapCommonCompile.GetProjPath(path);
  17. var proj = TapCommonCompile.ParseProjPath(projPath);
  18. var target = TapCommonCompile.GetUnityTarget(proj);
  19. var unityFrameworkTarget = TapCommonCompile.GetUnityFrameworkTarget(proj);
  20. if (TapCommonCompile.CheckTarget(target))
  21. {
  22. Debug.LogError("Unity-iPhone is NUll");
  23. return;
  24. }
  25. proj.AddFrameworkToProject(unityFrameworkTarget, "CoreMotion.framework", false);
  26. proj.AddFrameworkToProject(unityFrameworkTarget, "Security.framework", false);
  27. proj.AddFrameworkToProject(unityFrameworkTarget, "SystemConfiguration.framework", false);
  28. proj.AddFrameworkToProject(unityFrameworkTarget, "iAd.framework", false);
  29. proj.AddFrameworkToProject(unityFrameworkTarget, "AdServices.framework", true);
  30. var parentFolder = Directory.GetParent(Application.dataPath)?.FullName;
  31. var plistFile = TapFileHelper.RecursionFilterFile(parentFolder + "/Assets/Plugins/", "TDS-Info.plist");
  32. if (!plistFile.Exists)
  33. {
  34. Debug.LogError("TapSDK Can't find TDS-Info.plist in Project/Assets/Plugins/!");
  35. }
  36. else
  37. {
  38. var dic = (Dictionary<string, object>) Plist.readPlist(plistFile.FullName);
  39. if (dic.ContainsKey("NSUserTrackingUsageDescription"))
  40. {
  41. proj.AddFrameworkToProject(unityFrameworkTarget, "AppTrackingTransparency.framework", true);
  42. proj.AddFrameworkToProject(unityFrameworkTarget, "AdSupport.framework", false);
  43. Debug.Log("TapDB add AdSupport and AppTracking framework");
  44. }
  45. }
  46. File.WriteAllText(projPath, proj.WriteToString());
  47. }
  48. }
  49. #endif
  50. }