com.guru.unity.sdk.core/Runtime/GuruConsent/Editor/PostBuildProcess/PostBuild.iOS.DMA.cs

61 lines
1.8 KiB
C#
Raw Normal View History

2024-02-23 03:37:53 +00:00
#if UNITY_IOS
namespace Guru.Editor
{
using UnityEditor;
using UnityEditor.Callbacks;
using UnityEngine;
using System.IO;
2024-02-23 03:37:53 +00:00
using UnityEditor.iOS.Xcode;
public class PostBuild_DMA
{
2024-02-23 03:37:53 +00:00
public static bool DefaultValue = true; // 配置注入默认值
[PostProcessBuild]
public static void OnPostProcessBuild(BuildTarget target, string buildPath)
{
if (target != BuildTarget.iOS) return;
2024-02-23 03:37:53 +00:00
SetInfoPlist(buildPath);
}
2024-02-23 03:37:53 +00:00
/// <summary>
/// inject default values
/// </summary>
/// <param name="buildPath"></param>
private static void SetInfoPlist(string buildPath)
{
var infoPlistPath = Path.Combine(buildPath, "Info.plist");
if (!File.Exists(infoPlistPath))
{
Debug.LogError("Info.plist not found");
return;
}
2024-02-23 03:37:53 +00:00
var plist = new PlistDocument();
plist.ReadFromFile(infoPlistPath);
var root = plist.root;
root.SetBoolean("GADDelayAppMeasurementInit", true);
//--------- set all default values ----------
root.SetBoolean("GOOGLE_ANALYTICS_DEFAULT_ALLOW_AD_STORAGE", DefaultValue);
root.SetBoolean("GOOGLE_ANALYTICS_DEFAULT_ALLOW_ANALYTICS_STORAGE", DefaultValue);
root.SetBoolean("GOOGLE_ANALYTICS_DEFAULT_ALLOW_AD_PERSONALIZATION_SIGNALS", DefaultValue);
root.SetBoolean("GOOGLE_ANALYTICS_DEFAULT_ALLOW_AD_USER_DATA", DefaultValue);
plist.WriteToFile(infoPlistPath);
Debug.Log($"<color=#88ff00>[Post] consent has inject dma default values {DefaultValue} to {infoPlistPath} </color>");
}
#endif
}
}