Skip to content

Commit 723fdd3

Browse files
author
Ram Parameswaran
committed
Update preprocessor directives for iOS post build setup and add request agent to all ad requests from plugin.
1 parent e55634b commit 723fdd3

19 files changed

+732
-239
lines changed

GoogleMobileAds.unitypackage

80.8 KB
Binary file not shown.

source/plugin/Assets/GoogleMobileAds/Editor/PostProcessor.cs

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
using UnityEditor.Callbacks;
55
using UnityEditor;
66

7-
#if UNITY_5
7+
#if (UNITY_5 && UNITY_IOS)
88
using UnityEditor.iOS.Xcode;
99
#endif
1010

@@ -30,25 +30,27 @@ public static void OnPostprocessBuild(BuildTarget target, string pathToBuiltProj
3030

3131
static void runPodUpdate(string path)
3232
{
33-
// Copy the podfile into the project.
34-
string podfile = "Assets/GoogleMobileAds/Editor/Podfile";
35-
string destpodfile = path + "/Podfile";
36-
if(!System.IO.File.Exists(destpodfile))
37-
{
38-
FileUtil.CopyFileOrDirectory(podfile, destpodfile);
39-
}
33+
#if !UNITY_CLOUD_BUILD
34+
// Copy the podfile into the project.
35+
string podfile = "Assets/GoogleMobileAds/Editor/Podfile";
36+
string destpodfile = path + "/Podfile";
37+
if(!System.IO.File.Exists(destpodfile))
38+
{
39+
FileUtil.CopyFileOrDirectory(podfile, destpodfile);
40+
}
4041

41-
try
42-
{
43-
CocoaPodHelper.Update(path);
44-
}
45-
catch (Exception e)
46-
{
47-
UnityEngine.Debug.Log("Could not create a new Xcode project with CocoaPods: " +
48-
e.Message);
49-
}
42+
try
43+
{
44+
CocoaPodHelper.Update(path);
45+
}
46+
catch (Exception e)
47+
{
48+
UnityEngine.Debug.Log("Could not create a new Xcode project with CocoaPods: " +
49+
e.Message);
50+
}
51+
#endif
5052

51-
#if UNITY_5
53+
#if (UNITY_5 && UNITY_IOS)
5254
string pbxprojPath = path + "/Unity-iPhone.xcodeproj/project.pbxproj";
5355
PBXProject project = new PBXProject();
5456
project.ReadFromString(File.ReadAllText(pbxprojPath));

source/plugin/Assets/GoogleMobileAds/Platforms/Android/Utils.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,13 +141,14 @@ public static AndroidJavaObject GetAdRequestJavaObject(AdRequest request)
141141
"tagForChildDirectedTreatment",
142142
request.TagForChildDirectedTreatment.GetValueOrDefault());
143143
}
144+
// Denote that the request is coming from this Unity plugin.
145+
adRequestBuilder.Call<AndroidJavaObject>("setRequestAgent",
146+
"unity-" + AdRequest.Version);
144147
AndroidJavaObject bundle = new AndroidJavaObject(BundleClassName);
145148
foreach (KeyValuePair<string, string> entry in request.Extras)
146149
{
147150
bundle.Call("putString", entry.Key, entry.Value);
148151
}
149-
// Denote that the request is coming from this Unity plugin.
150-
bundle.Call("putInt", "unity", 1);
151152
AndroidJavaObject extras = new AndroidJavaObject(AdMobExtrasClassName, bundle);
152153
adRequestBuilder.Call<AndroidJavaObject>("addNetworkExtras", extras);
153154
return adRequestBuilder.Call<AndroidJavaObject>("build");

source/plugin/Assets/GoogleMobileAds/Platforms/iOS/Externs.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ internal static extern void GADUTagForChildDirectedTreatment(
4444
[DllImport("__Internal")]
4545
internal static extern void GADUSetExtra(IntPtr request, string key, string value);
4646

47+
[DllImport("__Internal")]
48+
internal static extern void GADUSetRequestAgent(IntPtr request, string requestAgent);
49+
4750
[DllImport("__Internal")]
4851
internal static extern void GADURelease(IntPtr obj);
4952

source/plugin/Assets/GoogleMobileAds/Platforms/iOS/RewardBasedVideoAdClient.cs

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -92,33 +92,7 @@ public void CreateRewardBasedVideoAd()
9292
// Load an ad.
9393
public void LoadAd(AdRequest request, string adUnitId)
9494
{
95-
IntPtr requestPtr = Externs.GADUCreateRequest();
96-
foreach (string keyword in request.Keywords)
97-
{
98-
Externs.GADUAddKeyword(requestPtr, keyword);
99-
}
100-
foreach (string deviceId in request.TestDevices)
101-
{
102-
Externs.GADUAddTestDevice(requestPtr, deviceId);
103-
}
104-
if (request.Birthday.HasValue)
105-
{
106-
DateTime birthday = request.Birthday.GetValueOrDefault();
107-
Externs.GADUSetBirthday(requestPtr, birthday.Year, birthday.Month, birthday.Day);
108-
}
109-
if (request.Gender.HasValue)
110-
{
111-
Externs.GADUSetGender(requestPtr, (int)request.Gender.GetValueOrDefault());
112-
}
113-
if (request.TagForChildDirectedTreatment.HasValue)
114-
{
115-
Externs.GADUTagForChildDirectedTreatment(
116-
requestPtr, request.TagForChildDirectedTreatment.GetValueOrDefault());
117-
}
118-
foreach (KeyValuePair<string, string> entry in request.Extras)
119-
{
120-
Externs.GADUSetExtra(requestPtr, entry.Key, entry.Value);
121-
}
95+
IntPtr requestPtr = Utils.BuildAdRequest(request);
12296
Externs.GADURequestRewardBasedVideoAd(
12397
RewardBasedVideoAdPtr, requestPtr, adUnitId, userId);
12498
Externs.GADURelease(requestPtr);

source/plugin/Assets/GoogleMobileAds/Platforms/iOS/Utils.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public static IntPtr BuildAdRequest(AdRequest request)
5050
{
5151
Externs.GADUSetExtra(requestPtr, entry.Key, entry.Value);
5252
}
53+
Externs.GADUSetRequestAgent(requestPtr, "unity-" + AdRequest.Version);
5354
return requestPtr;
5455
}
5556
}

0 commit comments

Comments
 (0)