Skip to content

Commit

Permalink
Added helper method to get iOS device language
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathansligh-nimbus committed Sep 25, 2024
1 parent fef7f53 commit 639fd39
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
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
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

0 comments on commit 639fd39

Please sign in to comment.