Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unity Device Language Support #51

Merged
merged 6 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
2 changes: 1 addition & 1 deletion com.adsbynimbus.nimbus/Runtime/Plugins/RTB.Tests/Tests.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
7 changes: 0 additions & 7 deletions com.adsbynimbus.nimbus/Runtime/Plugins/RTB/OpenRTB.sln.meta

This file was deleted.

4 changes: 4 additions & 0 deletions com.adsbynimbus.nimbus/Runtime/Plugins/iOS/NimbusBinding.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down
11 changes: 11 additions & 0 deletions com.adsbynimbus.nimbus/Runtime/Plugins/iOS/NimbusHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ internal override Device GetDevice() {
(ConnectionType)_connectionTypeHelper.CallStatic<sbyte>("getConnectionType", ctx);

var _adInfo = _nimbus.CallStatic<AndroidJavaObject>("getAdIdInfo");
var cls = new AndroidJavaClass("java.util.Locale");
var locale = cls.CallStatic<AndroidJavaObject>("getDefault");
_deviceCache.Language = locale.Call<string>("getLanguage");
_deviceCache.Lmt = _adInfo.Call<bool>("isLimitAdTrackingEnabled") ? 1 : 0;
_deviceCache.Ifa = _adInfo.Call<string>("getId");
return _deviceCache;
Expand Down
4 changes: 4 additions & 0 deletions com.adsbynimbus.nimbus/Runtime/Scripts/Nimbus.Internal/IOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -137,6 +140,7 @@ internal override Device GetDevice() {
Make = "apple",
Model = _getDeviceModel(),
Osv = _getSystemVersion(),
Language = _getDeviceLanguage(),
Ext = new DeviceExt {
Ifv = _getVendorId()
},
Expand Down