デバイスデータの取得ガイド
Singularでは、正確な属性情報を取得するために、すべてのAPIリクエストに特定のデバイス識別子を含める必要があります。これらの識別子には以下が含まれます:
- Google PlayデバイスのGoogle Advertising ID (GAID) およびGoogle App Set ID (ASID)
- Google Play以外のAmazonデバイス用のAmazon Advertising ID
- 中国製Androidデバイス用のOpen Advertising ID (OAID)
- 上記のいずれにも該当しない場合は、非Google Playデバイス用のAndroid ID(ANDI)を使用します。
- iOSデバイス用の広告主識別子(IDFA)とベンダー識別子(IDFV)
Singularはまた、いくつかのモバイルデバイスのパラメータを必要とします:
- ロケール(例:en_US)
- デバイスのメーカー(例:Samsung)
- デバイスモデル(例:iPhone 12、Samsung Galaxy S21)
- ビルド(例:Build/13D15)
Singularはこれらの識別子を取得するためのコードスニペット例を提供しています。
デバイス情報クラスのサンプル
識別子
iOSに必要な識別子
- IDFVは全てのS2Sリクエストで必須。
- App Tracking Transparency Consentがユーザーによって提供された場合、IDFAが提供されるべきである。
- ATT Authorization Statusも必要。
広告主識別子(IDFA)の取得
広告主向け識別子(IDFA)は、広告主がユーザーのアクション(広告のクリックやアプリのインストールなど)を追跡し、特定のキャンペーンに関連付けるのに役立ち、正確な広告ターゲティングとキャンペーンの最適化を可能にします。
iOS 14.5以降、アプリがIDFAにアクセスする前に、ユーザーはApp Tracking Transparency(ATT)フレームワークを介してオプトインする必要があります。ユーザーがオプトインしない場合、IDFAは利用できず、トラッキング機能が制限されます。
ベンダー識別子(IDFV)の取得
IDFV(Identifier for Vendors)は、Appleがデバイスに割り当てる一意の識別子で、特定のベンダーまたはデベロッパーに固有のものです。特定のデバイス上の同じベンダーのすべてのアプリで一貫性が保たれるため、ベンダーはユーザーを個人的に特定することなく、そのアプリのエコシステム全体でユーザーの行動やインタラクションを追跡することができます。
- IDFAへのアクセスを試みる前に、ATTプロンプトが表示され、処理されていることを確認してください。
- ATTを使用している場合は、IDFAをキャプチャし、Singular APIリクエストで使用するためにサーバーに戻します。
- IDFVをキャプチャし、Singular APIリクエストで使用するためにサーバーに戻す。
例ATT認証ステータスを要求して、コンソールログからIDFAとIDFVを取得する。
以下は、コンソールログでIDFA(広告主の識別子)とIDFV(ベンダーの識別子)の両方を取得するためのObjective-CとSwiftのコードスニペットです。このコードには、iOS 14.5からIDFAにアクセスするために必要なATT(App Tracking Transparency)パーミッションの処理が含まれています。
#import <AdSupport/AdSupport.h>
#import <AppTrackingTransparency/AppTrackingTransparency.h>
#import <UIKit/UIKit.h>
- (void)retrieveIdentifiers {
// Request ATT authorization (iOS 14.5+)
[ATTrackingManager requestTrackingAuthorizationWithCompletionHandler:^(ATTrackingManagerAuthorizationStatus status) {
dispatch_async(dispatch_get_main_queue(), ^{
switch (status) {
case ATTrackingManagerAuthorizationStatusAuthorized: {
// ATT authorized, retrieve IDFA
NSUUID *idfa = [[ASIdentifierManager sharedManager] advertisingIdentifier];
NSLog(@"IDFA: %@", [idfa UUIDString]);
break;
}
case ATTrackingManagerAuthorizationStatusDenied:
case ATTrackingManagerAuthorizationStatusRestricted:
case ATTrackingManagerAuthorizationStatusNotDetermined:
// ATT not authorized or not determined
NSLog(@"Tracking not authorized or not determined.");
break;
default:
NSLog(@"Unknown ATT status.");
break;
}
// Retrieve IDFV (always available)
NSUUID *idfv = [[UIDevice currentDevice] identifierForVendor];
if (idfv != nil) {
NSLog(@"IDFV: %@", [idfv UUIDString]);
} else {
NSLog(@"Unable to retrieve IDFV.");
}
});
}];
}
// Call the method to retrieve identifiers
[self retrieveIdentifiers];
import AdSupport
import AppTrackingTransparency
import UIKit
func retrieveIdentifiers() {
// Request ATT authorization (iOS 14.5+)
ATTrackingManager.requestTrackingAuthorization { status in
DispatchQueue.main.async {
switch status {
case .authorized:
// ATT authorized, retrieve IDFA
let idfa = ASIdentifierManager.shared().advertisingIdentifier.uuidString
print("IDFA: \(idfa)")
case .denied, .restricted, .notDetermined:
// ATT not authorized or not determined
print("Tracking not authorized or not determined.")
@unknown default:
print("Unknown ATT status.")
}
// Retrieve IDFV (always available)
if let idfv = UIDevice.current.identifierForVendor?.uuidString {
print("IDFV: \(idfv)")
} else {
print("Unable to retrieve IDFV.")
}
}
}
}
// Call the function to retrieve identifiers
retrieveIdentifiers()
- IDFA:iOS 14.5+からATT許可が必要。ユーザーの同意がない場合、IDFAはすべてのゼロを返します。
- IDFV: 常に利用可能であり、Singular API Requestsで常に提供されるべきである。
必須Android識別子(Google Playデバイス)
- ASIDは、すべてのS2Sリクエストで必須です。
- AIFA(GAID)は、利用可能な場合に提供されるべきである。
Google広告識別子(GAID)の取得
Google Advertising Identifier(GAID)は、単数形ではAIFA、またはAndroid Advertising ID(AAID)とも呼ばれ、Android端末に割り当てられる一意のユーザーリセット可能な識別子です。これにより、広告主やアプリ開発者は、アプリ全体のユーザーアクション(広告のクリックやアプリのインストールなど)を追跡して特定のキャンペーンに関連付けることができ、ユーザーのプライバシーを維持しながら、正確な広告ターゲティングとキャンペーンの最適化が可能になります。
build.gradleファイルにGoogle Play Servicesに必要な依存関係が追加されていることを確認してください:
dependencies {
implementation 'com.google.android.gms:play-services-ads-identifier:17.0.0'
}
アプリのビルドがAndroid 12/APIレベル31以上をターゲットにしている場合は、AndroidManifest.xml 、Google Advertising IDにアクセスするためのパーミッションを追加してください:
<uses-permission android:name="com.google.android.gms.permission.AD_ID" />
このメソッドを使用するには、アクティビティまたはアプリケーションクラスから呼び出すだけです:
AdIdUtils.getGoogleAdId(getApplicationContext());
Google広告ID(GAID)を取得するJavaコード
import android.content.Context;
import android.os.AsyncTask;
import android.util.Log;
import com.google.android.gms.ads.identifier.AdvertisingIdClient;
import com.google.android.gms.ads.identifier.AdvertisingIdClient.Info;
public class AdIdUtils {
// Method to retrieve the Google Advertising ID (GAID)
public static void getGoogleAdId(Context context) {
// Running the task in a background thread
AsyncTask.execute(new Runnable() {
@Override
public void run() {
try {
// Retrieve the Advertising ID info
Info adInfo = AdvertisingIdClient.getAdvertisingIdInfo(context);
// Get the GAID (Google Advertising ID)
String adId = adInfo.getId();
// Check if "Limit Ad Tracking" is enabled by the user
boolean isLimitAdTrackingEnabled = adInfo.isLimitAdTrackingEnabled();
// Log the results
Log.d("GoogleAdID", "Advertising ID: " + adId);
Log.d("GoogleAdID", "Limit Ad Tracking Enabled: " + isLimitAdTrackingEnabled);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
}
build.gradleファイルにGoogle Play Servicesの必要な依存関係が追加されていることを確認してください:
dependencies {
implementation 'com.google.android.gms:play-services-ads-identifier:17.0.0'
}
アプリのビルドがAndroid 12/APIレベル31以上をターゲットにしている場合は、AndroidManifest.xml 、Google Advertising IDにアクセスするためのパーミッションを追加してください:
<uses-permission android:name="com.google.android.gms.permission.AD_ID" />
使用方法
この関数を使用するには、ViewModel や lifecycleScope を使用したアクティビティなど、コルーチンスコープから呼び出す必要があります。アクティビティ内でこの関数を呼び出す例を以下に示します:
import androidx.lifecycle.lifecycleScope
import kotlinx.coroutines.launch
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
// Launch a coroutine to fetch the Google Ad ID
lifecycleScope.launch {
val googleAdId = AdIdUtils.getGoogleAdId(applicationContext)
Log.d("MainActivity", "Retrieved Google Ad ID: $googleAdId")
}
}
}
Google Advertising ID (GAID) を取得する Java コード
import android.content.Context
import android.util.Log
import com.google.android.gms.ads.identifier.AdvertisingIdClient
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
object AdIdUtils {
// Function to retrieve Google Advertising ID (GAID) using coroutines
suspend fun getGoogleAdId(context: Context): String? {
return withContext(Dispatchers.IO) {
try {
// Retrieve the Advertising ID info
val adInfo = AdvertisingIdClient.getAdvertisingIdInfo(context)
// Get the GAID (Google Advertising ID)
val adId = adInfo.id
// Check if "Limit Ad Tracking" is enabled by the user
val isLimitAdTrackingEnabled = adInfo.isLimitAdTrackingEnabled
// Log the results
Log.d("GoogleAdID", "Advertising ID: $adId")
Log.d("GoogleAdID", "Limit Ad Tracking Enabled: $isLimitAdTrackingEnabled")
adId
} catch (e: Exception) {
e.printStackTrace()
null
}
}
}
}
アプリセットID(ASID)の取得
Android App Set IDは、開発者がプライバシーに配慮した方法で自身のアプリ全体のユーザーを追跡する方法を提供します。特に分析や不正防止に役立ちますが、パーソナライズ広告や計測などの広告目的には使用できません。
build.gradleファイルにGoogle Play Servicesに必要な依存関係が追加されていることを確認してください:
dependencies {
implementation 'com.google.android.gms:play-services-appset:16.1.0'
}
使用方法
この関数を使用するには、アクティビティまたはアプリケーションクラスからこの関数を呼び出します:
AppSetIdUtils.getAppSetId(getApplicationContext());
アプリセットIDを取得するJavaコード
import android.content.Context;
import android.util.Log;
import com.google.android.gms.appset.AppSet;
import com.google.android.gms.appset.AppSetIdClient;
import com.google.android.gms.appset.AppSetIdInfo;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.android.gms.tasks.Task;
public class AppSetIdUtils {
// Method to retrieve the App Set ID
public static void getAppSetId(Context context) {
// Get the AppSetIdClient instance
AppSetIdClient client = AppSet.getClient(context);
// Retrieve the App Set ID information asynchronously
Task<AppSetIdInfo> task = client.getAppSetIdInfo();
task.addOnSuccessListener(new OnSuccessListener<AppSetIdInfo>() {
@Override
public void onSuccess(AppSetIdInfo info) {
// Get the App Set ID and its scope
String appSetId = info.getId();
int scope = info.getScope();
// Log the results
Log.d("AppSetID", "App Set ID: " + appSetId);
Log.d("AppSetID", "Scope: " + (scope == AppSetIdInfo.SCOPE_DEVELOPER ? "Developer" : "App"));
}
}).addOnFailureListener(e -> {
// Handle any errors that occur during retrieval
Log.e("AppSetID", "Failed to retrieve App Set ID", e);
});
}
}
build.gradleファイルにGoogle Playサービスに必要な依存関係が追加されていることを確認してください:
dependencies {
implementation 'com.google.android.gms:play-services-appset:16.1.0'
}
使用方法
この関数を使用するには、アクティビティまたはアプリケーションクラスからこの関数を呼び出します:
AppSetIdUtils.getAppSetId(applicationContext)
アプリセットIDを取得するKotlinコード
import android.content.Context
import android.util.Log
import com.google.android.gms.appset.AppSet
import com.google.android.gms.appset.AppSetIdClient
import com.google.android.gms.tasks.Task
object AppSetIdUtils {
// Function to retrieve the App Set ID
fun getAppSetId(context: Context) {
// Get the AppSetIdClient instance
val client: AppSetIdClient = AppSet.getClient(context)
// Retrieve the App Set ID information asynchronously
val task: Task<AppSetIdInfo> = client.appSetIdInfo
task.addOnSuccessListener { info ->
// Get the App Set ID and its scope
val appSetId: String = info.id
val scope: Int = info.scope
// Log the results
Log.d("AppSetID", "App Set ID: $appSetId")
Log.d("AppSetID", "Scope: ${if (scope == AppSetIdInfo.SCOPE_DEVELOPER) "Developer" else "App"}")
}.addOnFailureListener { exception ->
// Handle any errors that occur during retrieval
Log.e("AppSetID", "Failed to retrieve App Set ID", exception)
}
}
}
必要なAndroid識別子(Google Play以外のデバイス)
ASIDまたはAIFAがない場合:
- AMID(Amazon識別子)を提供する必要があります。Amazonデバイスのみ。
アマゾンID(AMID)の取得
AndroidアプリでAmazon Advertising IDを取得するには、Settings.Secureクラスを使ってIDを取得し、ユーザーの広告トラッキング設定を確認します。以下は、Amazonのドキュメントが提供する情報に基づいた、クリーンでシンプルなコード例です:
Advertising IDが利用できない可能性のあるシナリオ(例えば、Fire OS以外のデバイスやFire OSの古いバージョンなど)にも対応できるようにしてください。
この識別子を広告や分析の目的で使用する場合は、ユーザーのLimit Ad Tracking preferenceを常に尊重してください。このコードは、Amazonのガイドラインに従って、Fire OS 5.1以降を実行しているAmazon Fireデバイスで動作するはずです。
ContentResolver.ContentResolverを渡すことで、アクティビティやサービスからこのメソッドを呼び出すことができます:
// Example usage in an Activity
AdvertisingIdHelper.getAmazonAdvertisingId(getContentResolver());
Amazon Advertising ID (AMID)を取得するJavaコード
import android.content.ContentResolver;
import android.provider.Settings;
import android.provider.Settings.SettingNotFoundException;
import android.util.Log;
public class AdvertisingIdHelper {
public static void getAmazonAdvertisingId(ContentResolver contentResolver) {
String advertisingID = "";
boolean limitAdTracking = false;
try {
// Get user's ad tracking preference
limitAdTracking = (Settings.Secure.getInt(contentResolver, "limit_ad_tracking") == 0) ? false : true;
// Get the Amazon Advertising ID
advertisingID = Settings.Secure.getString(contentResolver, "advertising_id");
// Log the values for demonstration purposes
Log.d("AdvertisingID", "Amazon Advertising ID: " + advertisingID);
Log.d("LimitAdTracking", "Limit Ad Tracking: " + limitAdTracking);
} catch (SettingNotFoundException e) {
// Handle case where settings are not available (e.g., non-Fire OS devices)
Log.e("AdvertisingID", "Advertising ID not supported on this device", e);
}
}
}
ContentResolverを渡すことで、アクティビティまたはサービスからこのメソッドを呼び出すことができます:
// Example usage in an Activity
AdvertisingIdHelper.getAmazonAdvertisingId(contentResolver)
Amazon Advertising ID(AMID)を取得するKotlinコード
import android.content.ContentResolver
import android.provider.Settings
import android.util.Log
object AdvertisingIdHelper {
fun getAmazonAdvertisingId(contentResolver: ContentResolver) {
try {
// Get user's ad tracking preference
val limitAdTracking = Settings.Secure.getInt(contentResolver, "limit_ad_tracking") != 0
// Get the Amazon Advertising ID
val advertisingID = Settings.Secure.getString(contentResolver, "advertising_id")
// Log the values for demonstration purposes
Log.d("AdvertisingID", "Amazon Advertising ID: $advertisingID")
Log.d("LimitAdTracking", "Limit Ad Tracking: $limitAdTracking")
} catch (e: Settings.SettingNotFoundException) {
// Handle case where settings are not available (e.g., non-Fire OS devices)
Log.e("AdvertisingID", "Advertising ID not supported on this device", e)
}
}
}
- OAID(Open Advertising Identifier)を提供する必要があります。中国国内の端末
オープン広告ID(OAID)の取得について
Open Advertising Identifier(OAID)は、Android端末、特に中国で製造された端末の広告目的で使用される一意の匿名識別子です。中国市場など、Google Playサービスが利用できない、またはサポートされていないデバイスのために、Googleの広告ID(GAID)の代替としてMobile Security Alliance(MSA)によって導入されました。
OAIDは主に、Google Playサービスが制限されている環境における広告のアトリビューションやユーザー追跡のために使用され、広告主や開発者は匿名性を維持しながらユーザーの行動を追跡することができます。
OAIDは、ファーウェイやシャオミなどのブランドを含む、ほとんどの中国製アンドロイド端末で利用できる。MSA SDKまたはHuawei Mobile Services(HMS)を使用してアクセスできます。
build.gradle ファイルに MSA SDK に必要な依存関係が含まれていることを確認してください。
dependencies {
implementation 'com.bun.msa.sdk:msa:1.0.26' // Example version; check for the latest one
}
OAIDを取得するJavaコード
import android.os.Bundle;
import android.util.Log;
import androidx.appcompat.app.AppCompatActivity;
import com.bun.msa.sdk.DeviceId;
import com.bun.msa.sdk.DeviceIdSupplier;
import com.bun.msa.sdk.IIdentifierListener;
public class MainActivity extends AppCompatActivity {
private static final String TAG = "OAIDExample";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Initialize and request OAID
getOAID();
}
private void getOAID() {
try {
// Create a DeviceId instance and request OAID asynchronously
DeviceId deviceId = new DeviceId(this);
deviceId.getDeviceIds(new IIdentifierListener() {
@Override
public void onSupport(boolean isSupport, DeviceIdSupplier supplier) {
if (isSupport && supplier != null) {
// Retrieve OAID from supplier
String oaid = supplier.getOAID();
Log.d(TAG, "OAID: " + oaid);
} else {
Log.e(TAG, "OAID not supported on this device");
}
}
});
} catch (Exception e) {
Log.e(TAG, "Error retrieving OAID", e);
}
}
}
MSA SDK をプロジェクトに追加します:Java バージョンと同様に、MSA SDK をプロジェクトに統合する必要があります。build.gradle ファイルに正しい依存関係があることを確認してください:
dependencies {
implementation 'com.bun.msa.sdk:msa:1.0.26' // Example version; check for the latest one
}
OAIDを取得するKotlinコード
import android.os.Bundle
import android.util.Log
import androidx.appcompat.app.AppCompatActivity
import com.bun.msa.sdk.DeviceId
import com.bun.msa.sdk.DeviceIdSupplier
import com.bun.msa.sdk.IIdentifierListener
class MainActivity : AppCompatActivity() {
companion object {
private const val TAG = "OAIDExample"
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
// Initialize and request OAID
getOAID()
}
private fun getOAID() {
try {
val deviceId = DeviceId(this)
deviceId.getDeviceIds(object : IIdentifierListener {
override fun onSupport(isSupport: Boolean, supplier: DeviceIdSupplier?) {
if (isSupport && supplier != null) {
// Retrieve OAID from supplier
val oaid = supplier.oAID
Log.d(TAG, "OAID: $oaid")
} else {
Log.e(TAG, "OAID not supported on this device")
}
}
})
} catch (e: Exception) {
Log.e(TAG, "Error retrieving OAID", e)
}
}
}
- 他のデバイス識別子が存在しない場合は、ANDI(Android ID)を提供することができます。
Android ID(ANDI)の取得
Android IDは、デバイスの最初のセットアップ時にAndroidオペレーティングシステムによって生成される一意の64ビット識別子です。Android IDはデバイスの寿命を通じて永続するように設計されていますが、ファクトリーリセットなどの特定の条件下ではリセットすることができます。
Android IDは各デバイスに固有で、Android 8.0(Oreo)からはアプリごと、ユーザーごとにスコープされるようになった。つまり、同じデバイス上の異なるアプリは、同じ署名キーを共有しない限り、異なるAndroid IDを受け取ることになります。
Android IDは、デバイスがファクトリーリセットされない限り、またはOTA(Over-the-Air)アップデート後にアプリがアンインストールされ再インストールされない限り、一定に保たれます。
AndroidアプリでAndroid IDを取得するには、以下のコード・スニペットを使用します:
import android.provider.Settings;
import android.content.Context;
String androidId = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);
ContentResolverを渡すことで、アクティビティやサービスからこのメソッドを呼び出すことができます:
import android.os.Bundle
import android.provider.Settings
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
// Find the TextView in the layout to display the Android ID
val textView: TextView = findViewById(R.id.textView)
// Retrieve the Android ID
val androidId: String = Settings.Secure.getString(contentResolver, Settings.Secure.ANDROID_ID)
}
}
必須ウェブ識別子
- SDIDは全てのS2Sリクエストに必要です。
Singular Web SDK デバイスID(SDID)の取得
説明
Singular Web SDKが実装されている必要があります。
使用方法このメソッドを使用するには、Singular SDKが初期化された後、ウェブサイトのコードからこのメソッドを呼び出します:
window.singularSdk.getSingularDeviceId()
必要なモバイルデバイスパラム
- Locale、Device Make、Device Model、Buildは全てのS2Sリクエストに必要です。
Locale、Device Make、Model、Buildの取得
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import <sys/sysctl.h>
// Retrieve the Locale
NSString *retrieveLocale() {
NSString *locale = [[NSLocale currentLocale] localeIdentifier];
NSLog(@"Locale: %@", locale);
return locale;
}
// Retrieve the Manufacturer
NSString *retrieveManufacturer() {
// Set the Device Make to Apple
return @"Apple";
}
// Retrieve the Device Model
NSString *deviceModel() {
size_t bufferSize = 64;
char model[bufferSize];
int status = sysctlbyname("hw.machine", model, &bufferSize, NULL, 0);
if (status == 0) {
NSString *deviceModel = [NSString stringWithCString:model encoding:NSUTF8StringEncoding];
NSLog(@"Device Model: %@", deviceModel);
return deviceModel;
} else {
NSLog(@"Unable to retrieve device model.");
return nil;
}
}
// Retrieve the Build Version
NSString *buildVersion() {
size_t bufferSize = 64;
char build[bufferSize];
int status = sysctlbyname("kern.osversion", build, &bufferSize, NULL, 0);
if (status == 0) {
NSString *buildVersion = [NSString stringWithCString:build encoding:NSUTF8StringEncoding];
NSLog(@"Build Version: %@", buildVersion);
return buildVersion;
} else {
NSLog(@"Unable to retrieve build version.");
return nil;
}
}
// Example usage
int main(int argc, const char * argv[]) {
@autoreleasepool {
// Retrieve Locale
NSString *locale = retrieveLocale();
// Retrieve Device Make
NSString *make = retrieveManufacturer();
// Retrieve Device Model
NSString *model = deviceModel();
// Retrieve Build Version
NSString *build = buildVersion();
// Log results
if (locale) {
NSLog(@"Locale: %@", locale);
}
if (make) {
NSLog(@"Device Make: %@", make);
}
if (model) {
NSLog(@"Device Model: %@", model);
}
if (build) {
NSLog(@"Build Version: %@", build);
}
}
return 0;
}
import Foundation
// Retrieve the Locale
func retrieveLocale() -> String {
let locale = Locale.current.identifier
print("Locale: \(locale)")
return locale
}
// Retrieve the Device Model
import UIKit
func deviceModel() -> String? {
var systemInfo = utsname()
uname(&systemInfo)
let machineMirror = Mirror(reflecting: systemInfo.machine)
let identifier = machineMirror.children.reduce("") { identifier, element in
guard let value = element.value as? Int8, value != 0 else { return identifier }
return identifier + String(UnicodeScalar(UInt8(value)))
}
print("Device Model: \(identifier)")
return identifier
}
// Retrieve the Build Version
func buildVersion() -> String? {
var size: Int = 0
sysctlbyname("kern.osversion", nil, &size, nil, 0)
var build = [CChar](repeating: 0, count: size)
sysctlbyname("kern.osversion", &build, &size, nil, 0)
let buildVersion = String(cString: build)
print("Build Version: \(buildVersion)")
return buildVersion
}
// Example usage:
let locale = retrieveLocale()
print("Locale: \(locale)")
let deviceMake = "Apple"
print("Device Make: \(deviceMake)")
if let model = deviceModel() {
print("Device Model: \(model)")
}
if let build = buildVersion() {
print("Build Version: \(build)")
}
// Locale - lc= query parameter
String locale = Locale.getDefault().toString(); // Converts Locale object to string
// Make - ma= query parameter
String deviceMake = Build.MANUFACTURER; // Gets the device manufacturer name
// Model - mo= query parameter
String deviceModel = Build.MODEL; // Gets the device model
// Build - bd= query parameter
String build = "Build/" + Build.ID; // Gets the build ID and appends it to "Build/"
// Locale - lc= query parameter
val locale: String = Locale.getDefault().toString() // Converts Locale object to string
// Make - ma= query parameter
val deviceMake: String = Build.MANUFACTURER // Gets the device manufacturer name
// Model - mo= query parameter
val deviceModel: String = Build.MODEL // Gets the device model
// Build - bd= query parameter
val build: String = "Build/" + Build.ID // Gets the build ID and appends it to "Build/"