From 035fd02033bc01831ef06b3ded647ca36c22e2e3 Mon Sep 17 00:00:00 2001 From: jonathansligh-nimbus Date: Thu, 26 Sep 2024 15:26:05 -0500 Subject: [PATCH] Unity Device Language Support (#51) * Needed to remove test files from unity so it will compile. * Added "atype" for EIDs.UIDs and added logging for Bid Requests and Bid Responses. * Added code for Android specifically, now to do iOS. * Added helper method to get iOS device language * Cleaning up --- .../Plugins/RTB.Tests/Properties/AssemblyInfo.cs | 2 +- .../Runtime/Plugins/RTB.Tests/Tests.cs | 2 +- .../Runtime/Plugins/RTB/OpenRTB.sln.meta | 7 ------- .../Runtime/Plugins/iOS/NimbusBinding.mm | 4 ++++ .../Runtime/Plugins/iOS/NimbusHelper.swift | 11 +++++++++++ .../Runtime/Scripts/Nimbus.Internal/Android.cs | 3 +++ .../Runtime/Scripts/Nimbus.Internal/IOS.cs | 4 ++++ 7 files changed, 24 insertions(+), 9 deletions(-) delete mode 100644 com.adsbynimbus.nimbus/Runtime/Plugins/RTB/OpenRTB.sln.meta diff --git a/com.adsbynimbus.nimbus/Runtime/Plugins/RTB.Tests/Properties/AssemblyInfo.cs b/com.adsbynimbus.nimbus/Runtime/Plugins/RTB.Tests/Properties/AssemblyInfo.cs index f6080307..9d075407 100644 --- a/com.adsbynimbus.nimbus/Runtime/Plugins/RTB.Tests/Properties/AssemblyInfo.cs +++ b/com.adsbynimbus.nimbus/Runtime/Plugins/RTB.Tests/Properties/AssemblyInfo.cs @@ -1,4 +1,4 @@ -#if !UNITY_EDITOR && !UNITY_IOS && !UNITY_ANDROID +#if !UNITY_EDITOR && !UNITY_IOS && !UNITY_ANDROID using System.Reflection; using System.Runtime.InteropServices; diff --git a/com.adsbynimbus.nimbus/Runtime/Plugins/RTB.Tests/Tests.cs b/com.adsbynimbus.nimbus/Runtime/Plugins/RTB.Tests/Tests.cs index 20241175..e80a1b92 100644 --- a/com.adsbynimbus.nimbus/Runtime/Plugins/RTB.Tests/Tests.cs +++ b/com.adsbynimbus.nimbus/Runtime/Plugins/RTB.Tests/Tests.cs @@ -1,4 +1,4 @@ -#if !UNITY_EDITOR && !UNITY_IOS && !UNITY_ANDROID +#if !UNITY_EDITOR && !UNITY_IOS && !UNITY_ANDROID using System; using System.Diagnostics; using Newtonsoft.Json; diff --git a/com.adsbynimbus.nimbus/Runtime/Plugins/RTB/OpenRTB.sln.meta b/com.adsbynimbus.nimbus/Runtime/Plugins/RTB/OpenRTB.sln.meta deleted file mode 100644 index 664f6c42..00000000 --- a/com.adsbynimbus.nimbus/Runtime/Plugins/RTB/OpenRTB.sln.meta +++ /dev/null @@ -1,7 +0,0 @@ -fileFormatVersion: 2 -guid: 832eb7ec059ba4298a3ee76879f31a57 -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/com.adsbynimbus.nimbus/Runtime/Plugins/iOS/NimbusBinding.mm b/com.adsbynimbus.nimbus/Runtime/Plugins/iOS/NimbusBinding.mm index 97efc44e..383ce52b 100644 --- a/com.adsbynimbus.nimbus/Runtime/Plugins/iOS/NimbusBinding.mm +++ b/com.adsbynimbus.nimbus/Runtime/Plugins/iOS/NimbusBinding.mm @@ -56,6 +56,10 @@ int _getConnectionType() { const char* _getDeviceModel() { return strdup([[NimbusHelper getDeviceModel] UTF8String]); } + + const char* _getDeviceLanguage() { + return strdup([[NimbusHelper getDeviceLanguage] UTF8String]); + } const char* _getSystemVersion() { return strdup([[NimbusHelper getSystemVersion] UTF8String]); diff --git a/com.adsbynimbus.nimbus/Runtime/Plugins/iOS/NimbusHelper.swift b/com.adsbynimbus.nimbus/Runtime/Plugins/iOS/NimbusHelper.swift index 0eac823a..7af8b951 100644 --- a/com.adsbynimbus.nimbus/Runtime/Plugins/iOS/NimbusHelper.swift +++ b/com.adsbynimbus.nimbus/Runtime/Plugins/iOS/NimbusHelper.swift @@ -32,6 +32,17 @@ import AppTrackingTransparency UIDevice.current.nimbusModelName } + @objc public class func getDeviceLanguage() -> String? { + guard let preferred = Locale.preferredLanguages.first else { + // Edge case fallback as I saw some old ObjC case where preferredLanguages + // returned an empty array (causing a crash) and Apple Docs don't say this array must not + // be empty despite not being able to delete all preferred languages on an iOS device. + return Locale.current.languageCode + } + + return Locale(identifier: preferred).languageCode + } + @objc public class func getSystemVersion() -> String { UIDevice.current.systemVersion } diff --git a/com.adsbynimbus.nimbus/Runtime/Scripts/Nimbus.Internal/Android.cs b/com.adsbynimbus.nimbus/Runtime/Scripts/Nimbus.Internal/Android.cs index 8512a34a..d42f1143 100644 --- a/com.adsbynimbus.nimbus/Runtime/Scripts/Nimbus.Internal/Android.cs +++ b/com.adsbynimbus.nimbus/Runtime/Scripts/Nimbus.Internal/Android.cs @@ -103,6 +103,9 @@ internal override Device GetDevice() { (ConnectionType)_connectionTypeHelper.CallStatic("getConnectionType", ctx); var _adInfo = _nimbus.CallStatic("getAdIdInfo"); + var cls = new AndroidJavaClass("java.util.Locale"); + var locale = cls.CallStatic("getDefault"); + _deviceCache.Language = locale.Call("getLanguage"); _deviceCache.Lmt = _adInfo.Call("isLimitAdTrackingEnabled") ? 1 : 0; _deviceCache.Ifa = _adInfo.Call("getId"); return _deviceCache; diff --git a/com.adsbynimbus.nimbus/Runtime/Scripts/Nimbus.Internal/IOS.cs b/com.adsbynimbus.nimbus/Runtime/Scripts/Nimbus.Internal/IOS.cs index 775bc476..2c970030 100644 --- a/com.adsbynimbus.nimbus/Runtime/Scripts/Nimbus.Internal/IOS.cs +++ b/com.adsbynimbus.nimbus/Runtime/Scripts/Nimbus.Internal/IOS.cs @@ -51,6 +51,9 @@ private static extern void _renderAd(int adUnitInstanceId, string bidResponse, b [DllImport("__Internal")] private static extern string _getDeviceModel(); + + [DllImport("__Internal")] + private static extern string _getDeviceLanguage(); [DllImport("__Internal")] private static extern string _getSystemVersion(); @@ -137,6 +140,7 @@ internal override Device GetDevice() { Make = "apple", Model = _getDeviceModel(), Osv = _getSystemVersion(), + Language = _getDeviceLanguage(), Ext = new DeviceExt { Ifv = _getVendorId() },