Skip to content

Commit 6319cd9

Browse files
Mobile Ads Developer Relationscopybara-github
authored andcommitted
Add the API to fetch underlying GMA Android or iOS SDK version.
PiperOrigin-RevId: 705625362
1 parent 71ec0b8 commit 6319cd9

File tree

8 files changed

+53
-0
lines changed

8 files changed

+53
-0
lines changed

ChangeLog.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
Google Mobile Ads Unity Plugin Change Log
22

3+
**************
4+
Version Next
5+
**************
6+
- Added GetPlatformVersion API to MobileAds class to be able to fetch the version info of the underlying GMA Android or iOS SDK.
7+
38
**************
49
Version 9.4.0
510
**************

source/plugin/Assets/GoogleMobileAds/Api/MobileAds.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,22 @@ public static void DisableSDKCrashReporting()
206206
Instance.client.DisableSDKCrashReporting();
207207
}
208208

209+
/// <summary>
210+
/// Gets the underlying Google Mobile Ads Android or iOS SDK version for the active
211+
/// platform.
212+
/// </summary>
213+
/// <remarks>
214+
/// When running on the Unity editor, this method returns the Google Mobile Ads Unity SDK
215+
/// version.
216+
/// </remarks>
217+
/// <returns>
218+
/// The Google Mobile Ads Android or iOS SDK version for the platform the app is running on.
219+
/// </returns>
220+
public static Version GetPlatformVersion()
221+
{
222+
return Instance.client.GetSDKVersion();
223+
}
224+
209225
/// <summary>
210226
/// Preloads ads for the given configurations.
211227
/// </summary>

source/plugin/Assets/GoogleMobileAds/Common/IMobileAdsClient.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ void Preload(List<PreloadConfiguration> configurations,
6666
// Set Global Request Configuration to Mobile Ads SDK
6767
void SetRequestConfiguration(RequestConfiguration requestConfiguration);
6868

69+
// Returns the Mobile Ads SDK version.
70+
Version GetSDKVersion();
71+
6972
// Get Mobile Ads SDK's Global Request Configuration
7073
RequestConfiguration GetRequestConfiguration();
7174

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,15 @@ public int GetDeviceSafeWidth()
137137
return Utils.GetScreenWidth();
138138
}
139139

140+
public Version GetSDKVersion()
141+
{
142+
AndroidJavaClass mobileAdsClass = new AndroidJavaClass(Utils.MobileAdsClassName);
143+
AndroidJavaObject androidSDKVersion =
144+
mobileAdsClass.CallStatic<AndroidJavaObject>("getVersion");
145+
string versionString = androidSDKVersion.Call<string>("toString");
146+
return new Version(versionString);
147+
}
148+
140149
#region Callbacks from OnInitializationCompleteListener.
141150

142151
public void onInitializationComplete(AndroidJavaObject initStatus)

source/plugin/Assets/GoogleMobileAds/Platforms/Unity/MobileAdsClient.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,11 @@ public int GetDeviceSafeWidth()
128128
return 0;
129129
}
130130

131+
public Version GetSDKVersion()
132+
{
133+
return new Version(AdRequest.Version);
134+
}
135+
131136
public void CreateBannerView(string adUnitId, AdSize adSize, AdPosition position) {}
132137

133138
public void CreateBannerView(string adUnitId, AdSize adSize, int positionX, int positionY) {}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,9 @@ internal static extern void GAMUSetPublisherProvidedID(IntPtr request,
156156
[DllImport("__Internal")]
157157
internal static extern void GADUSetPreloadConfigurationBufferSize(IntPtr preloadConfiguration, uint bufferSize);
158158

159+
[DllImport("__Internal")]
160+
internal static extern string GADUMobileAdsVersion();
161+
159162
[DllImport("__Internal")]
160163
internal static extern IntPtr GADUCreateRequestConfiguration();
161164

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,12 @@ public int GetDeviceSafeWidth()
105105
return Externs.GADUDeviceSafeWidth();
106106
}
107107

108+
public Version GetSDKVersion()
109+
{
110+
string iOSVersion = Externs.GADUMobileAdsVersion();
111+
return new Version(iOSVersion);
112+
}
113+
108114
public void Preload(List<PreloadConfiguration> configurations,
109115
Action<PreloadConfiguration> onAdAvailable,
110116
Action<PreloadConfiguration> onAdsExhausted)

source/plugin/Assets/Plugins/iOS/GADUInterface.m

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,12 @@ void GADUDisableSDKCrashReporting() {
218218
[GADMobileAds.sharedInstance disableSDKCrashReporting];
219219
}
220220

221+
// Returns the version number of the GMA iOS SDK.
222+
const char* GADUMobileAdsVersion() {
223+
GADVersionNumber version = [GADMobileAds.sharedInstance versionNumber];
224+
return cStringCopy(GADGetStringFromVersionNumber(version).UTF8String);
225+
}
226+
221227
float GADUDeviceScale() { return UIScreen.mainScreen.scale; }
222228

223229
void GADUSetIntegerPreference(const char *key, NSInteger value) {

0 commit comments

Comments
 (0)