标头 — X-Device-Info header-x-device-info
NOTE
此页面上的内容仅供参考。 使用此API需要来自Adobe的当前许可证。 不允许未经授权使用。
概述 overview
X-Device-Info 请求标头包含与实际流设备相关的客户端信息(设备、连接和应用程序)。
语法 syntax
指令 directives
<设备信息>
JSON元素的Base64-encoded
值,至少包含下表要求标记的属性。
示例 examples
// Device information
// {
// "primaryHardwareType" : "MobilePhone",
// "model":"SM-S901U",
// "vendor":"samsung",
// "version":"r0q",
// "manufacturer":"samsung",
// "osName":"Android",
// "osVersion":"14"
// }
// BASE64-encoded
// ewogICJwcmltYXJ5SGFyZHdhcmVUeXBlIiA6ICJNb2JpbGVQaG9uZSIsCiAgIm1vZGVsIjoiU00tUzkwMVUiLAogICJ2ZW5kb3I
// iOiJzYW1zdW5nIiwKICAidmVyc2lvbiI6InIwcSIsCiAgIm1hbnVmYWN0dXJlciI6InNhbXN1bmciLAogICJvc05hbWUiOiJBbmRyb
// 2lkIiwKICAib3NWZXJzaW9uIjoiMTQiCn0=
X-Device-Info: ewogICJwcmltYXJ5SGFyZHdhcmVUeXBlIiA6ICJNb2JpbGVQaG9uZSIsCiAgIm1vZGVsIjoiU00tUzkwMVUiLAogICJ2ZW5kb3IiOiJzYW1zdW5nIiwKICAidmVyc2lvbiI6InIwcSIsCiAgIm1hbnVmYWN0dXJlciI6InNhbXN1bmciLAogICJvc05hbWUiOiJBbmRyb2lkIiwKICAib3NWZXJzaW9uIjoiMTQiCn0=
指南 cookbooks
IMPORTANT
提供了代码段和文档资源以供参考。
代码片段并非详尽无遗,可能需要进行额外的修改才能在您的项目中正常工作。
无论实际实施如何,
X-Device-Info
标头都必须包含一个值,其格式如指令部分中所述。浏览器 browsers
对于在浏览器中运行的客户端应用程序,可以省略X-Device-Info
标头,因为浏览器将自动在User-Agent
标头中发送所需的最小信息集。
您仍然可以使用X-Device-Info
标头提供有关设备、连接和应用程序的附加信息,以防您的客户端应用程序集成了提供设备识别机制的库或服务。
移动设备 mobile-devices
iOS和iPadOS ios-ipados
要为运行iOS或iPadOS的设备构建X-Device-Info
标头,您可以参考以下文档及以下代码片段:
+ (NSString *)computeClientInformation {
struct utsname u;
uname(&u);
NSString *hardware = [NSString stringWithCString:u.machine encoding:NSUTF8StringEncoding];
UIDevice *device = [UIDevice currentDevice];
NSString *deviceType;
switch (UI_USER_INTERFACE_IDIOM()) {
case UIUserInterfaceIdiomPhone:
deviceType = @"MobilePhone";
break;
case UIUserInterfaceIdiomPad:
deviceType = @"Tablet";
break;
case UIUserInterfaceIdiomTV:
deviceType = @"TV";
break;
default:
deviceType = @"Unknown";
}
CGRect screenRect = [[UIScreen mainScreen] bounds];
NSNumber *screenWidth = @((float) screenRect.size.width);
NSNumber *screenHeight = @((float) screenRect.size.height);
Reachability *reachability = [Reachability reachabilityForInternetConnection];
[reachability startNotifier];
NetworkStatus status = [reachability currentReachabilityStatus];
NSString *connectionType;
if (status == NotReachable) {
connectionType = @"notConnected";
} else if (status == ReachableViaWiFi) {
connectionType = @"WiFi";
} else if (status == ReachableViaWWAN) {
connectionType = @"cellular";
}
NSMutableDictionary *clientInformation = [@{
@"type": deviceType,
@"model": device.model,
@"vendor": @"Apple",
@"manufacturer": @"Apple",
@"version": [hardware stringByReplacingOccurrencesOfString:device.model withString:@""],
@"osName": device.systemName,
@"osVersion": device.systemVersion,
@"displayWidth": screenWidth,
@"displayHeight": screenHeight,
@"connectionType": connectionType,
@"applicationId": @"REF30"
} mutableCopy];
NSError *error;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:clientInformation options:NSJSONWritingPrettyPrinted error:&error];
NSString *base64Encoded = [jsonData base64EncodedStringWithOptions:0];
return base64Encoded;
}
设备信息可通过以下方式构建:
键
Source
值(示例)
模型
uname.machine
iPhone
供应商
硬编码
Apple
制造商
硬编码
Apple
版本
uname.machine
8,1
显示宽度
UIScreen.mainScreen
320
displayheight
UIScreen.mainScreen
568
操作系统名称
UIDevice.systemName
iOS
osVersion
UIDevice.systemVersion
10.2
连接信息可通过以下方式构建:
键
Source
值(示例)
connectionType
[可达性currentReachabilityStatus]
connectionSecure
应用程序信息可通过以下方式构建:
键
Source
值(示例)
applicationId
硬编码
REF30
Android android
要为运行Android的设备生成X-Device-Info
标头,您可以参考以下文档以及下面的代码片段:
- Build类的Android开发人员文档。
private JSONObject computeClientInformation() {
String LOGGING_TAG = "DefineClass.class";
JSONObject clientInformation = new JSONObject();
String connectionType;
try {
ConnectivityManager cm = (ConnectivityManager) getContext().getSystemService(CONNECTIVITY_SERVICE);
NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
if (activeNetwork != null && activeNetwork.isConnectedOrConnecting()) {
switch (activeNetwork.getType()) {
case ConnectivityManager.TYPE_WIFI: {
connectionType = "WIFI";
break;
}
case ConnectivityManager.TYPE_BLUETOOTH: {
connectionType = "BLUETOOTH";
break;
}
case ConnectivityManager.TYPE_MOBILE: {
connectionType = "MOBILE";
break;
}
case ConnectivityManager.TYPE_ETHERNET: {
connectionType = "ETHERNET";
break;
}
case ConnectivityManager.TYPE_VPN: {
connectionType = "VPN";
break;
}
case ConnectivityManager.TYPE_DUMMY: {
connectionType = "DUMMY";
break;
}
case ConnectivityManager.TYPE_MOBILE_DUN: {
connectionType = "MOBILE_DUN";
break;
}
case ConnectivityManager.TYPE_WIMAX: {
connectionType = "WIMAX";
break;
}
default:
connectionType = ConnectivityManager.EXTRA_OTHER_NETWORK_INFO;
}
} else {
connectionType = ConnectivityManager.EXTRA_NO_CONNECTIVITY;
}
} catch (Exception e) {
connectionType = "notAccessible";
}
try {
clientInformation.put("model", Build.MODEL);
clientInformation.put("vendor", Build.BRAND);
clientInformation.put("manufacturer", Build.MANUFACTURER);
clientInformation.put("version", Build.DEVICE);
clientInformation.put("osName", "Android");
clientInformation.put("osVersion", Build.VERSION.RELEASE);
clientInformation.put("connectionType", connectionType);
clientInformation.put("applicationId", "REF30");
} catch (JSONException e) {
Log.e(LOGGING_TAG, e.getMessage());
}
return Base64.encodeToString(clientInformation.toString().getBytes(), Base64.NO_WRAP);
}
设备信息可通过以下方式构建:
键
Source
值(示例)
模型
Build.MODEL
GT-I9505
供应商
Build.BRAND
三星
制造商
Build.MANUFACTURER
三星
版本
Build.DEVICE
jflte
显示宽度
DisplayMetrics.widthPixels
600
displayheight
DisplayMetrics.heightPixels
800
操作系统名称
硬编码
Android
osVersion
Build.VERSION.RELEASE
5.0.1
连接信息可通过以下方式构建:
键
Source
值(示例)
connectionType
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
getSystemService(Context.CONNECTIVITY_SERVICE).getActiveNetworkInfo().getType()
"WIFI","BLUETOOTH","MOBILE","ETHERNET","VPN","DUMMY","MOBILE_DUN","WIMAX","notAccessible"
connectionSecure
应用程序信息可通过以下方式构建:
键
Source
值(示例)
applicationId
硬编码
REF30
TV连接的设备 tv-connected-devices
tvOS tvos
要为运行tvOS的设备生成X-Device-Info
标头,您可以参考以下文档及以下代码片段:
+ (NSString *)computeClientInformation {
struct utsname u;
uname(&u);
NSString *hardware = [NSString stringWithCString:u.machine encoding:NSUTF8StringEncoding];
UIDevice *device = [UIDevice currentDevice];
NSString *deviceType;
switch (UI_USER_INTERFACE_IDIOM()) {
case UIUserInterfaceIdiomPhone:
deviceType = @"MobilePhone";
break;
case UIUserInterfaceIdiomPad:
deviceType = @"Tablet";
break;
case UIUserInterfaceIdiomTV:
deviceType = @"TV";
break;
default:
deviceType = @"Unknown";
}
CGRect screenRect = [[UIScreen mainScreen] bounds];
NSNumber *screenWidth = @((float) screenRect.size.width);
NSNumber *screenHeight = @((float) screenRect.size.height);
Reachability *reachability = [Reachability reachabilityForInternetConnection];
[reachability startNotifier];
NetworkStatus status = [reachability currentReachabilityStatus];
NSString *connectionType;
if (status == NotReachable) {
connectionType = @"notConnected";
} else if (status == ReachableViaWiFi) {
connectionType = @"WiFi";
} else if (status == ReachableViaWWAN) {
connectionType = @"cellular";
}
NSMutableDictionary *clientInformation = [@{
@"type": deviceType,
@"model": device.model,
@"vendor": @"Apple",
@"manufacturer": @"Apple",
@"version": [hardware stringByReplacingOccurrencesOfString:device.model withString:@""],
@"osName": device.systemName,
@"osVersion": device.systemVersion,
@"displayWidth": screenWidth,
@"displayHeight": screenHeight,
@"connectionType": connectionType,
@"applicationId": @"REF30"
} mutableCopy];
NSError *error;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:clientInformation options:NSJSONWritingPrettyPrinted error:&error];
NSString *base64Encoded = [jsonData base64EncodedStringWithOptions:0];
return base64Encoded;
}
设备信息可通过以下方式构建:
键
Source
值(示例)
模型
uname.machine
AppleTV
供应商
硬编码
Apple
制造商
硬编码
Apple
版本
uname.machine
8,1
显示宽度
UIScreen.mainScreen
1920
displayheight
UIScreen.mainScreen
1080
操作系统名称
UIDevice.systemName
tvOS
osVersion
UIDevice.systemVersion
10.2
连接信息可通过以下方式构建:
键
Source
值(示例)
connectionType
[可达性currentReachabilityStatus]
connectionSecure
应用程序信息可通过以下方式构建:
键
Source
值(示例)
applicationId
硬编码
REF30
Fire操作系统 fireos
要为运行Fire OS的设备生成X-Device-Info
标头,您可以参考以下文档:
- Build类的Android开发人员文档。
- 识别Fire TV设备的Amazon开发人员文档。
设备信息可通过以下方式构建:
键
Source
值(示例)
模型
Build.MODEL
AFTM
供应商
Build.BRAND
Amazon
制造商
Build.MANUFACTURER
Amazon
版本
Build.DEVICE
蒙托亚
显示宽度
DisplayMetrics.widthPixels
displayheight
DisplayMetrics.heightPixels
操作系统名称
硬编码
Android
osVersion
Build.VERSION.RELEASE
5.1.1
连接信息可通过以下方式构建:
键
Source
值(示例)
connectionType
connectionSecure
应用程序信息可通过以下方式构建:
键
Source
值(示例)
applicationId
硬编码
REF30
Roku OS rokuos
要为运行Roku OS的设备生成X-Device-Info
标头,您可以参考以下文档:
- ifDeviceInfo的Roku开发人员文档。
设备信息可通过以下方式构建:
键
Source
值(示例)
模型
硬编码
“Roku”
供应商
ifDeviceInfo.GetModelDetails().VendorName
“Sharp”、“Roku”
制造商
ifDeviceInfo.GetModelDetails().VendorName
“Sharp”、“Roku”
版本
ifDeviceInfo.GetModelDetails().ModelNumber
“5303X”
显示宽度
ifDeviceInfo.GetDisplaySize().w
1920
displayheight
ifDeviceInfo.GetDisplaySize().h
1080
操作系统名称
硬编码
“Roku”
osVersion
ifDeviceInfo.getVersion()
连接信息可通过以下方式构建:
键
Source
值(示例)
connectionType
ifDeviceInfo.GetConnectionType()
“WifiConnection”、“WiredConnection”
connectionSecure
硬编码
如果连接是有线的,则为true
应用程序信息可通过以下方式构建:
键
Source
值(示例)
applicationId
硬编码
REF30
recommendation-more-help
3f5e655c-af63-48cc-9769-2b6803cc5f4b