Skip to content

Commit be1b964

Browse files
Merge pull request #3 from SourcePointUSA/DIA-2026-revive-unity-sdk
[DIA-2026] Update / Improve Unity SDK
2 parents 5132c8d + bb0676d commit be1b964

File tree

50 files changed

+3010
-45
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+3010
-45
lines changed

Assets/ConsentManagementProvider/Editor/CMPPostProcessBuild.cs

Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
1-
using System.Collections;
2-
using System.Collections.Generic;
3-
using UnityEngine;
1+
#if UNITY_IOS
42
using UnityEditor;
53
using UnityEditor.Callbacks;
64
using UnityEditor.iOS.Xcode;
7-
using System.Diagnostics;
8-
95
using System.IO;
10-
using System.Linq;
116
using UnityEditor.iOS.Xcode.Extensions;
12-
using Debug = UnityEngine.Debug;
137

148
public static class CMPPostProcessBuild
159
{
@@ -23,36 +17,64 @@ public static void OnPostProcessBuild(BuildTarget buildTarget, string buildPath)
2317
PBXProject pbxProject = new PBXProject();
2418
string projPath = buildPath + "/Unity-Iphone.xcodeproj/project.pbxproj";
2519
pbxProject.ReadFromFile(projPath);
20+
string unityProjectGuid = pbxProject.ProjectGuid();
2621
string unityMainTargetGuid = pbxProject.GetUnityMainTargetGuid();
27-
28-
ConfigureFrameworks(pbxProject, unityMainTargetGuid);
22+
23+
pbxProject.AddBuildProperty(unityMainTargetGuid, "LIBRARY_SEARCH_PATHS", "\"$(TOOLCHAIN_DIR)/usr/lib/swift/$(PLATFORM_NAME)\" \"/usr/lib/swift\"");
24+
pbxProject.AddBuildProperty(unityProjectGuid, "ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES", "YES");
25+
26+
ConfigureFrameworks(pbxProject, unityProjectGuid);
2927
TieBridgingHeader(pbxProject, unityMainTargetGuid);
3028
EnableCppModules(pbxProject);
3129
EnableObjectiveCExceptions(pbxProject);
32-
//LinkBinaryWithLibraries(pbxProject, unityMainGUID);
33-
// EnableSwift(pbxProject, targetGuid);
30+
EnableBitcode(pbxProject, unityProjectGuid, false);
31+
// EnableBitcode(pbxProject, unityMainTargetGuid, false);
32+
33+
// LinkBinaryWithLibraries(pbxProject, unityMainGUID);
34+
// LinkBinaryWithLibraries(pbxProject,unityMainTargetGuid, "libswiftWebKit.tbd");
35+
// EnableSwift(pbxProject, unityProjectGuid);
3436

3537
pbxProject.WriteToFile(projPath);
38+
39+
string plistPath = buildPath + "/Info.plist";
40+
AddParameterToInfoPlist(plistPath);
3641
}
3742
}
3843

44+
static void AddParameterToInfoPlist(string plistPath)
45+
{
46+
PlistDocument plist = new PlistDocument();
47+
plist.ReadFromString(File.ReadAllText(plistPath));
48+
PlistElementDict rootDict = plist.root;
49+
50+
// var buildKey = "Privacy - Tracking Usage Description";
51+
var buildKey = "NSUserTrackingUsageDescription";
52+
rootDict.SetString(buildKey,"This identifier will be used to deliver personalized ads to you.");
53+
54+
File.WriteAllText(plistPath, plist.WriteToString());
55+
}
56+
3957
static void ConfigureFrameworks(PBXProject pbxProject, string targetGuid)
4058
{
41-
pbxProject.AddBuildProperty(targetGuid, "LD_RUNPATH_SEARCH_PATHS", "@executable_path/Frameworks $(PROJECT_DIR)/lib/$(CONFIGURATION) $(inherited)");
42-
pbxProject.AddBuildProperty(targetGuid, "FRAMERWORK_SEARCH_PATHS",
59+
pbxProject.AddBuildProperty(targetGuid, "LD_RUNPATH_SEARCH_PATHS", "/usr/lib/swift");
60+
/*pbxProject.AddBuildProperty(targetGuid, "FRAMERWORK_SEARCH_PATHS",
4361
"$(inherited) $(PROJECT_DIR) $(PROJECT_DIR)/Frameworks");
4462
pbxProject.AddBuildProperty(targetGuid, "DYLIB_INSTALL_NAME_BASE", "@rpath");
4563
pbxProject.AddBuildProperty(targetGuid, "LD_DYLIB_INSTALL_NAME",
46-
"@executable_path/../Frameworks/$(EXECUTABLE_PATH)");
64+
"@executable_path/../Frameworks/$(EXECUTABLE_PATH)");*/
4765
}
4866

4967
static void TieBridgingHeader(PBXProject pbxProject, string targetGuid)
5068
{
51-
pbxProject.SetBuildProperty(targetGuid, "ENABLE_BITCODE", "NO");
5269
pbxProject.SetBuildProperty(targetGuid, "SWIFT_OBJC_BRIDGING_HEADER", "Libraries/Plugins/iOS/Source/UnityPlugin-Bridging-Header.h");
5370
pbxProject.SetBuildProperty(targetGuid, "SWIFT_OBJC_INTERFACE_HEADER_NAME", "UnityController.h");
5471
}
55-
72+
73+
private static void EnableBitcode(PBXProject pbxProject, string targetGuid, bool enabled)
74+
{
75+
pbxProject.SetBuildProperty(targetGuid, "ENABLE_BITCODE", enabled ? "YES" : "NO");
76+
}
77+
5678
static void EnableCppModules(PBXProject pbxProject)
5779
{
5880
pbxProject.AddBuildProperty(pbxProject.GetUnityMainTargetGuid(), "CLANG_ENABLE_MODULES", "YES");
@@ -78,4 +100,5 @@ static void EnableSwift(PBXProject pbxProject, string targetGuid)
78100
pbxProject.AddBuildProperty(targetGuid, "COREML_CODEGEN_LANGUAGE", "Swift");
79101
pbxProject.AddBuildProperty(targetGuid, "ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES", "YES");
80102
}
81-
}
103+
}
104+
#endif

Assets/ConsentManagementProvider/Editor/CMPPostProcessBuild.cs.meta

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Binary file not shown.
Binary file not shown.

Assets/ConsentManagementProvider/Plugins/iOS/Source/UnityController.m

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -109,61 +109,68 @@ - (void) addTargetingParamForCampaignType : (int) campaignType : (char*) key : (
109109
// NSLog(@"params => %@", params);
110110
}
111111

112-
-(void) consrtuctLib : (int) accountId _:(char*) propName _: (int) arrSize _: (int[]) campaignTypes _: (int) campaignsEnvironment _: (long) timeOutSeconds
112+
-(void) consrtuctLib : (int) accountId _:(char*) propName _: (int) arrSize _: (int[]) campaignTypes _: (int) campaignsEnvironment _: (long) timeOutSeconds
113113
{
114114
SPError * err = [self checkIfPropNameNotNull: propName];
115115
if(err != nil)
116116
{
117117
[self onErrorWithError:err];
118118
}else{
119119
NSString* nsPropName = [self convertCharToNSString:propName];;
120-
120+
121121
@try
122122
{
123123
SPPropertyName *propertyName = [[SPPropertyName alloc] init:nsPropName error:NULL];
124-
124+
125125
SPCampaign * gdpr = nil;
126126
SPCampaign * ccpa = nil;
127127
SPCampaign * ios14 = nil;
128-
128+
129129
NSMutableDictionary<NSString *, NSString *> * gdprParams;
130130
NSMutableDictionary<NSString *, NSString *> * ccpaParams;
131131
NSMutableDictionary<NSString *, NSString *> * ios14Params;
132-
132+
133133
for (int index=0; index < arrSize; index++)
134134
{
135135
SPCampaignType type = campaignTypes[index];
136136
// NSLog(@"and type is... %ld", (long)type);
137-
137+
138138
NSNumber * nsCampaignType = [NSNumber numberWithInt:index];
139139
NSMutableDictionary<NSString *, NSString *> * campaignParams = params[[nsCampaignType stringValue]];
140-
SPCampaignEnv * env = campaignsEnvironment;
141-
140+
// SPCampaignEnv * env = campaignsEnvironment;
141+
142142
if(type == SPCampaignTypeGdpr)
143143
{
144144
gdprParams = campaignParams;
145145
if([gdprParams count] == 0){
146146
[gdprParams setObject:@"" forKey:@""];
147147
}
148+
// gdpr = [[SPCampaign alloc]
149+
// initWithEnvironment:env
150+
// targetingParams:gdprParams];
148151
gdpr = [[SPCampaign alloc]
149-
initWithEnvironment:env
150-
targetingParams:gdprParams];
152+
initWithTargetingParams:gdprParams];
153+
151154
}else if(type == SPCampaignTypeCcpa){
152155
ccpaParams = campaignParams;
153156
if([ccpaParams count] == 0){
154157
[ccpaParams setObject:@"" forKey:@""];
155158
}
159+
// ccpa = [[SPCampaign alloc]
160+
// initWithEnvironment:env
161+
// targetingParams: ccpaParams];
156162
ccpa = [[SPCampaign alloc]
157-
initWithEnvironment:env
158-
targetingParams: ccpaParams];
163+
initWithTargetingParams: ccpaParams];
159164
}else if(type == SPCampaignTypeIos14){
160165
ios14Params = campaignParams;
161166
if([ios14Params count] == 0){
162167
[ios14Params setObject:@"" forKey:@""];
163168
}
169+
// ios14 = [[SPCampaign alloc]
170+
// initWithEnvironment:env
171+
// targetingParams: ios14Params];
164172
ios14 = [[SPCampaign alloc]
165-
initWithEnvironment:env
166-
targetingParams: ios14Params];
173+
initWithTargetingParams: ios14Params];
167174
}else{
168175
SPError *myErr = [SPError errorWithDomain:@"SPConsentManager"
169176
code:100
@@ -174,14 +181,19 @@ -(void) consrtuctLib : (int) accountId _:(char*) propName _: (int) arrSize _: (i
174181
}
175182
}
176183
// NSLog(@"%@ ||| %@ ||| %@", gdpr.description, ccpa.description, ios14.description);
177-
184+
178185
SPCampaigns * campaigns = [[SPCampaigns alloc]
179186
initWithGdpr: gdpr
180187
ccpa: ccpa
181188
ios14: ios14];
189+
190+
SPCampaignEnv * env = campaignsEnvironment;
191+
NSLog(@" ENVIRONMENT: %ld", (long)env);
192+
182193
consentManager = [[SPConsentManager alloc]
183194
initWithAccountId:accountId
184195
propertyName: propertyName
196+
campaignsEnv: env
185197
campaigns: campaigns
186198
delegate: self];
187199
consentManager.messageTimeoutInSeconds = timeOutSeconds;
@@ -294,4 +306,4 @@ - (void)onConsentReadyWithUserData:(SPUserData *)userData {
294306
UnitySendMessage([self getGOName], "OnConsentReady", [self convertNSStringToChar:[userData toJSON]]);
295307
}
296308

297-
@end
309+
@end

Assets/ConsentManagementProvider/Scripts/wrapper/Android/SpClientProxy.cs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,23 @@ void onUIFinished(AndroidJavaObject view)
3131
ConsentMessenger.Broadcast<IOnConsentUIFinished>();
3232
}
3333

34-
void onAction(AndroidJavaObject view, AndroidJavaObject actionType)
34+
AndroidJavaObject onAction(AndroidJavaObject view, AndroidJavaObject actionType)
3535
{
36-
CONSENT_ACTION_TYPE unwrappedType = (CONSENT_ACTION_TYPE)actionType.Call<int>("getCode");
37-
CmpDebugUtil.Log("I've reached the C# onAction: " + unwrappedType);
36+
CmpDebugUtil.Log("I've reached the C# onAction!");
37+
38+
CmpDebugUtil.Log("Trying to unwrap ActionType... ");
39+
AndroidJavaObject wrapper = actionType.Call<AndroidJavaObject>("getActionType");
40+
CONSENT_ACTION_TYPE unwrappedType = (CONSENT_ACTION_TYPE)wrapper.Call<int>("getCode");
41+
CmpDebugUtil.Log("Unwrapped ActionType is: " + unwrappedType);
42+
43+
CmpDebugUtil.Log("Trying to put \"pb_key\", \"pb_value\" in pubData");
44+
AndroidJavaObject pubData = actionType.Call<AndroidJavaObject>("getPubData");
45+
pubData.Call<AndroidJavaObject>("put", "pb_key", "pb_value");
46+
CmpDebugUtil.Log("PUT IS SUCCESSFUL");
47+
3848
ConsentMessenger.Broadcast<IOnConsentAction>(unwrappedType);
49+
CmpDebugUtil.Log("Now I'll return actionType back to Java...");
50+
return actionType;
3951
}
4052

4153
void onConsentReady(string spConsents)
Binary file not shown.

Assets/ConsentManagementProvider/Plugins/Android/cmp.meta renamed to Assets/ExternalDependencyManager.meta

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/ConsentManagementProvider/xcframework.meta renamed to Assets/ExternalDependencyManager/Editor.meta

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/ExternalDependencyManager/Editor/1.2.175.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)