update: [DMA] 完善 iOS 取值逻辑

deeplink
胡宇飞 2024-02-23 11:37:53 +08:00
parent 897f39e6d9
commit 1bfbce04f1
7 changed files with 44 additions and 16 deletions

View File

@ -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
/// <summary>
/// inject default values
/// </summary>
/// <param name="buildPath"></param>
private static void SetInfoPlist(string buildPath)
{
var infoPlistPath = Path.Combine(buildPath, "Info.plist");
@ -30,8 +34,20 @@ namespace Guru.Editor
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($"<color=#88ff00>[Post] consent has inject dma default values {DefaultValue} to {infoPlistPath} </color>");
}

View File

@ -158,6 +158,18 @@ extern "C" {
callbackName = [NSString stringWithUTF8String:method];
}
// 获取GDPR状态码
const char* unityGetTCFValue(){
NSString *purposeConsents = [NSUserDefaults.standardUserDefaults
stringForKey:@"IABTCF_PurposeConsents"];
if( purposeConsents == nil){
return "";
}
return [U3DConsent stringToChar: purposeConsents];
}
}

View File

@ -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 ----------

View File

@ -4,6 +4,6 @@ namespace Guru
{
void Init(string objectName, string callbackName);
void RequestGDPR(string deviceId = "", int debugGeography = -1);
string GetDMAValue();
string GetPurposesValue();
}
}

View File

@ -53,7 +53,7 @@ namespace Guru
/// 获取 DMA 字段
/// </summary>
/// <returns></returns>
public string GetDMAValue()
public string GetPurposesValue()
{
#if UNITY_ANDROID
if (!_initSuccess) return "";

View File

@ -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 字段
/// </summary>
/// <returns></returns>
public string GetDMAValue()
public string GetPurposesValue()
{
#if UNITY_IOS
//TODO: ios return raw value
return unityGetTCFValue();
#endif
return "";
}

View File

@ -47,7 +47,7 @@ namespace Guru
/// 获取 DMA 字段
/// </summary>
/// <returns></returns>
public string GetDMAValue()
public string GetPurposesValue()
{
return "";
}