디바이스 데이터 검색 가이드
Singular는 정확한 어트리뷰션을 위해 모든 API 요청에 특정 디바이스 식별자를 포함해야 합니다. 이러한 식별자는 다음과 같습니다:
- 구글 플레이 기기용 구글 광고 ID(GAID) 및 구글 앱 세트 ID(ASID)
- 비 구글 플레이 아마존 디바이스를 위한 아마존 광고 ID
- 중국산 안드로이드 기기를 위한 오픈 광고 ID(OAID)
- 위의 어느 것도 사용할 수 없는 경우, 비구글 플레이 기기용 안드로이드 ID(ANDI)
- iOS 기기용 광고주 식별자(IDFA) 및 벤더 식별자(IDFV)
Singular에는 일부 모바일 기기 파라미터도 필요합니다:
- 로캘(예: en_US)
- 디바이스 제조사(예: 삼성)
- 장치 모델(예: 아이폰 12, 삼성 갤럭시 S21)
- 빌드(예: 빌드/13D15)
Singular는 이러한 식별자를 얻는 데 도움이 되는 코드 스니펫 예시를 제공하며, 아래에서 확인할 수 있습니다.
디바이스 정보 클래스 샘플
식별자
필수 iOS 식별자
- IDFV는 모든 S2S 요청에 필요합니다.
- 사용자가 앱 추적 투명성 동의를 제공한 경우 IDFA를 제공해야 합니다.
- ATT 승인 상태도 필요합니다.
광고주 식별자(IDFA) 검색하기
광고주 식별자(IDFA)는 광고주가 사용자 행동(예: 광고 클릭, 앱 설치)을 추적하고 특정 캠페인에 귀속시켜 정확한 광고 타겟팅과 캠페인 최적화를 가능하게 합니다.
iOS 14.5부터는 앱이 IDFA에 액세스하기 전에 사용자가 앱 추적 투명성(ATT) 프레임워크를 통해 옵트인해야 합니다. 사용자가 옵트인하지 않으면 IDFA를 사용할 수 없으므로 추적 기능이 제한됩니다.
공급업체용 식별자(IDFV) 검색하기
공급업체용 식별자(IDFV)는 Apple이 특정 공급업체 또는 개발자에게 특정한 기기에 할당하는 고유 식별자입니다. 특정 기기에서 동일한 공급업체의 모든 앱에서 일관되게 유지되므로 공급업체는 사용자를 개인적으로 식별하지 않고도 앱 생태계 전반에서 사용자 행동 및 상호 작용을 추적할 수 있습니다.
- IDFA에 액세스하기 전에 ATT 프롬프트가 표시되고 처리되는지 확인하세요.
- ATT를 사용하는 경우 IDFA를 캡처하여 서버로 다시 전달하여 Singular API 요청에 사용하세요.
- IDFV를 캡처하여 서버로 다시 전달하여 Singular API 요청에 사용하세요.
예시: 콘솔 로그를 사용하여 IDFA 및 IDFV 검색을 위한 ATT 권한 상태 요청하기
다음은 콘솔 로그를 사용하여 IDFA(광고주 식별자)와 IDFV(벤더 식별자)를 모두 검색하는 Objective-C 및 Swift 코드 스니펫입니다. 이 코드에는 iOS 14.5부터 IDFA에 액세스하는 데 필요한 ATT(앱 추적 투명성) 권한 처리가 포함되어 있습니다.
#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는 모든 0을 반환합니다.
- IDFV: 항상 사용 가능하며 Singular API 요청 시 항상 제공해야 합니다.
필수 Android 식별자(Google Play 기기)
- ASID는 모든 S2S 요청에 필수입니다.
- AIFA(GAID)는 가능한 경우 제공해야 합니다.
구글 광고 식별자(GAID) 검색하기
구글 광고 식별자(GAID)는 AIFA(Singular) 또는 안드로이드 광고 ID(AAID)라고도 하며, 안드로이드 기기에 할당된 사용자 재설정이 가능한 고유 식별자입니다. 광고주와 앱 개발자가 앱 전반의 사용자 행동(예: 광고 클릭, 앱 설치)을 추적하고 특정 캠페인에 어트리뷰션하여 정확한 광고 타겟팅과 캠페인 최적화를 수행하는 동시에 사용자 개인정보를 보호할 수 있도록 도와줍니다.
빌드.gradle 파일에 구글 플레이 서비스에 필요한 종속성을 추가했는지 확인하세요:
dependencies {
implementation 'com.google.android.gms:play-services-ads-identifier:17.0.0'
}
앱 빌드가 Android 12/API 레벨 31 이상을 대상으로 하는 경우, AndroidManifest.xml 에 Google 광고 ID에 액세스할 수 있는 권한을 추가하세요:
<uses-permission android:name="com.google.android.gms.permission.AD_ID" />
이 방법을 사용하려면 활동 또는 애플리케이션 클래스에서 호출하기만 하면 됩니다:
AdIdUtils.getGoogleAdId(getApplicationContext());
Google 광고 ID(GAID)를 검색하는 자바 코드
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();
}
}
});
}
}
빌드.gradle 파일에 Google Play 서비스에 필요한 종속성을 추가했는지 확인하세요:
dependencies {
implementation 'com.google.android.gms:play-services-ads-identifier:17.0.0'
}
앱 빌드가 Android 12/API 레벨 31 이상을 대상으로 하는 경우, AndroidManifest.xml 에 Google 광고 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 광고 ID(GAID)를 검색하는 자바 코드
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) 검색하기
안드로이드 앱 세트 ID는 개발자가 개인정보 보호를 고려한 방식으로 자신의 앱에서 사용자를 추적할 수 있는 방법을 제공합니다. 분석 및 사기 방지에 특히 유용하지만 개인 맞춤 광고나 측정과 같은 광고 목적으로는 사용할 수 없습니다.
빌드.gradle 파일에 Google Play 서비스에 필요한 종속성을 추가했는지 확인하세요:
dependencies {
implementation 'com.google.android.gms:play-services-appset:16.1.0'
}
사용법
이 함수를 사용하려면 활동 또는 애플리케이션 클래스에서 호출하기만 하면 됩니다:
AppSetIdUtils.getAppSetId(getApplicationContext());
앱 세트 ID를 검색하는 자바 코드
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);
});
}
}
빌드.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 식별자)를 제공해야 합니다. 아마존 디바이스만 해당.
아마존 ID(AMID) 검색하기
Android 앱에서 Amazon 광고 식별자를 캡처하려면 Settings.Secure 클래스를 사용하여 식별자를 검색하고 사용자의 광고 추적 기본 설정을 확인할 수 있습니다. 다음은 Amazon 문서에서 제공하는 정보를 기반으로 한 깔끔하고 간단한 코드 예제입니다:
광고 ID를 사용할 수 없는 시나리오(예: Fire OS가 아닌 기기 또는 이전 버전의 Fire OS)를 처리해야 합니다.
광고 또는 분석 목적으로 이 식별자를 사용할 때는 항상 사용자의 광고 추적 제한 기본 설정을 준수하세요. 이 코드는 Amazon의 가이드라인에 따라 Fire OS 5.1 이상을 실행하는 Amazon Fire 기기에서 작동해야 합니다.
활동이나 서비스에서 이 메서드를 호출하려면 ContentResolver를 전달하면 됩니다:
// Example usage in an Activity
AdvertisingIdHelper.getAmazonAdvertisingId(getContentResolver());
아마존 광고 ID(AMID) 검색을 위한 자바 코드
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 광고 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(오픈 광고 식별자)를 제공해야 합니다. 중국 국내 디바이스.
OAID(오픈 광고 ID) 검색하기
OAID(개방형 광고 식별자)는 Android 기기, 특히 중국에서 제조된 기기에서 광고 목적으로 사용되는 고유한 익명 식별자입니다. 중국 시장과 같이 구글 플레이 서비스를 사용할 수 없거나 지원하지 않는 기기에서 구글의 광고 ID(GAID)를 대체하기 위해 모바일 보안 연합(MSA)에서 도입했습니다.
OAID는 주로 Google Play 서비스가 제한된 환경에서 광고 어트리뷰션 및 사용자 추적에 사용되며, 광고주와 개발자가 익명성을 유지하면서 사용자 행동을 추적할 수 있도록 해줍니다.
OAID는 화웨이, 샤오미 등의 브랜드를 포함한 대부분의 중국 제조 안드로이드 기기에서 사용할 수 있습니다. MSA SDK 또는 화웨이 모바일 서비스(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)를 제공할 수 있습니다.
안드로이드 ID(ANDI) 검색하기
안드로이드 ID는 기기를 처음 설정할 때 안드로이드 운영 체제에서 생성하는 64비트 고유 식별자입니다. 장치 수명 기간 동안 영구적으로 유지되도록 설계되었지만 공장 초기화와 같은 특정 조건에서는 초기화될 수 있습니다.
안드로이드 ID는 각 디바이스마다 고유하며, 안드로이드 8.0(오레오)부터는 앱과 사용자별로 범위가 지정됩니다. 즉, 동일한 디바이스에 있는 여러 앱은 동일한 서명 키를 공유하지 않는 한 서로 다른 Android ID를 받게 됩니다.
Android ID는 디바이스를 초기화하거나 OTA(무선) 업데이트 후 앱을 삭제했다가 다시 설치하지 않는 한 일정하게 유지됩니다.
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 웹 SDK 디바이스 ID(SDID) 검색하기
설명
Singular 웹 SDK가 구현되어 있어야 합니다.
사용법이 방법을 사용하려면 Singular SDK가 초기화된 후 웹 사이트 코드에서 호출하기만 하면 됩니다:
window.singularSdk.getSingularDeviceId()
필수 모바일 디바이스 매개변수
- 로캘, 디바이스 제조사, 디바이스 모델, 빌드는 모든 S2S 요청에 필수입니다.
로캘, 디바이스 제조사, 모델 및 빌드 검색하기
#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/"