diff --git a/Runtime/GuruConsent/Editor/PostBuildProcess/PostBuild.iOS.DMA.cs b/Runtime/GuruConsent/Editor/PostBuildProcess/PostBuild.iOS.DMA.cs index 2e6fbe6..d0e100d 100644 --- a/Runtime/GuruConsent/Editor/PostBuildProcess/PostBuild.iOS.DMA.cs +++ b/Runtime/GuruConsent/Editor/PostBuildProcess/PostBuild.iOS.DMA.cs @@ -1,26 +1,30 @@ + +#if UNITY_IOS namespace Guru.Editor { using UnityEditor; using UnityEditor.Callbacks; using UnityEngine; using System.IO; - using NUnit.Framework; + using UnityEditor.iOS.Xcode; public class PostBuild_DMA { - + + public static bool DefaultValue = true; // 配置注入默认值 [PostProcessBuild] public static void OnPostProcessBuild(BuildTarget target, string buildPath) { if (target != BuildTarget.iOS) return; - + SetInfoPlist(buildPath); } -#if UNITY_IOS - - + /// + /// inject default values + /// + /// private static void SetInfoPlist(string buildPath) { var infoPlistPath = Path.Combine(buildPath, "Info.plist"); @@ -29,9 +33,21 @@ namespace Guru.Editor Debug.LogError("Info.plist not found"); return; } - - + 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($"[Post] consent has inject dma default values {DefaultValue} to {infoPlistPath} "); } diff --git a/Runtime/GuruConsent/Plugins/iOS/U3DConsent.mm b/Runtime/GuruConsent/Plugins/iOS/U3DConsent.mm index 760567d..514d51e 100644 --- a/Runtime/GuruConsent/Plugins/iOS/U3DConsent.mm +++ b/Runtime/GuruConsent/Plugins/iOS/U3DConsent.mm @@ -157,6 +157,18 @@ extern "C" { gameobjectName = [NSString stringWithUTF8String:gameobject]; callbackName = [NSString stringWithUTF8String:method]; } + + // 获取GDPR状态码 + const char* unityGetTCFValue(){ + NSString *purposeConsents = [NSUserDefaults.standardUserDefaults + stringForKey:@"IABTCF_PurposeConsents"]; + + if( purposeConsents == nil){ + return ""; + } + + return [U3DConsent stringToChar: purposeConsents]; + } } diff --git a/Runtime/GuruConsent/Runtime/Script/Consent/GuruConsent.cs b/Runtime/GuruConsent/Runtime/Script/Consent/GuruConsent.cs index 14111d3..0cb236c 100644 --- a/Runtime/GuruConsent/Runtime/Script/Consent/GuruConsent.cs +++ b/Runtime/GuruConsent/Runtime/Script/Consent/GuruConsent.cs @@ -69,7 +69,7 @@ namespace Guru private static void OnSDKCallback(string msg) { //-------- Fetch DMA status and report ----------- - var value = Agent?.GetDMAValue() ?? ""; + var value = Agent?.GetPurposesValue() ?? ""; GoogleDMAHelper.SetDMAStatus(value, _dmaMapRule); //------- message send to unity ---------- diff --git a/Runtime/GuruConsent/Runtime/Script/Consent/IConsentAgent.cs b/Runtime/GuruConsent/Runtime/Script/Consent/IConsentAgent.cs index 20fd1a6..4fa8cf7 100644 --- a/Runtime/GuruConsent/Runtime/Script/Consent/IConsentAgent.cs +++ b/Runtime/GuruConsent/Runtime/Script/Consent/IConsentAgent.cs @@ -4,6 +4,6 @@ namespace Guru { void Init(string objectName, string callbackName); void RequestGDPR(string deviceId = "", int debugGeography = -1); - string GetDMAValue(); + string GetPurposesValue(); } } \ No newline at end of file diff --git a/Runtime/GuruConsent/Runtime/Script/Consent/Impl/ConsentAgentAndroid.cs b/Runtime/GuruConsent/Runtime/Script/Consent/Impl/ConsentAgentAndroid.cs index 0b0cd58..eefa1a3 100644 --- a/Runtime/GuruConsent/Runtime/Script/Consent/Impl/ConsentAgentAndroid.cs +++ b/Runtime/GuruConsent/Runtime/Script/Consent/Impl/ConsentAgentAndroid.cs @@ -53,7 +53,7 @@ namespace Guru /// 获取 DMA 字段 /// /// - public string GetDMAValue() + public string GetPurposesValue() { #if UNITY_ANDROID if (!_initSuccess) return ""; diff --git a/Runtime/GuruConsent/Runtime/Script/Consent/Impl/ConsentAgentIOS.cs b/Runtime/GuruConsent/Runtime/Script/Consent/Impl/ConsentAgentIOS.cs index 2fd5605..20a589f 100644 --- a/Runtime/GuruConsent/Runtime/Script/Consent/Impl/ConsentAgentIOS.cs +++ b/Runtime/GuruConsent/Runtime/Script/Consent/Impl/ConsentAgentIOS.cs @@ -7,13 +7,13 @@ namespace Guru public class ConsentAgentIOS:IConsentAgent { private const string DLL_INTERNAL = "__Internal"; - #if UNITY_IOS [DllImport(DLL_INTERNAL)] private static extern void unityRequestGDPR(string deviceId, int debugGeography); // IOS 调用接口 - [DllImport(DLL_INTERNAL)] private static extern void unityInitSDK(string gameobject, string callback); // IOS 调用接口 + [DllImport(DLL_INTERNAL)] + private static extern string unityGetTCFValue(); // 获取 TFC 值 #endif private string _objName; @@ -47,10 +47,10 @@ namespace Guru /// 获取 DMA 字段 /// /// - public string GetDMAValue() + public string GetPurposesValue() { #if UNITY_IOS - //TODO: ios return raw value + return unityGetTCFValue(); #endif return ""; } diff --git a/Runtime/GuruConsent/Runtime/Script/Consent/Impl/ConsentAgentStub.cs b/Runtime/GuruConsent/Runtime/Script/Consent/Impl/ConsentAgentStub.cs index c3eaca4..b821a45 100644 --- a/Runtime/GuruConsent/Runtime/Script/Consent/Impl/ConsentAgentStub.cs +++ b/Runtime/GuruConsent/Runtime/Script/Consent/Impl/ConsentAgentStub.cs @@ -47,7 +47,7 @@ namespace Guru /// 获取 DMA 字段 /// /// - public string GetDMAValue() + public string GetPurposesValue() { return ""; }