先介绍下iOS设备的一些硬件标识
UDID: (unique device identifier) 设备唯一标识。*苹果已删除此接口
UUID: (universally unique identifier) 通用唯一设备。
NSString *uuid = [[NSUUID UUID] UUIDString];此函数每次执行会创建一个新的UUID。
IDFA、IDFV
idfa: 适用于对外:例如广告推广,换量等跨应用的用户追踪等
idfv: 适用于对内:例如分析用户在应用内的行为等
idfa:advertisingIdentifier
获取:
#import <AdSupport/AdSupport.h>
NSString *adId = [[[ASIdentifierManagersharedManager] advertisingIdentifier] UUIDString];
直译就是广告id,在同一个设备上的所有App都会取到相同的值,是苹果专门给各广告提供商用来追踪用户而设的,用户可以在 设置|隐私|广告追踪里重置此id的值,或限制此id的使用,故此id有可能会取不到值,但好在Apple默认是允许追踪的,而且一般用户都不知道有这么个设置,所以基本上用来监测推广效果,是戳戳有余了。
注意:由于idfa会出现取不到的情况,故绝不可以作为业务分析的主id,来识别用户。
idfv:identifierForVendor
获取:
NSString *idfv = [[[UIDevice currentDevice]identifierForVendor] UUIDString];
顾名思义,是给Vendor标识用户用的,每个设备在所属同一个Vender的应用里,都有相同的值。其中的Vender是指应用提供商,但准确点说,是通过BundleID的DNS反转的前两部分进行匹配,如果相同就是同一个Vender,例如对于com.somecompany.appone,com.somecompany.apptwo这两个BundleID来说,就属于同一个Vender,共享同一个idfv的值。和idfa不同的是,idfv的值是一定能取到的,所以非常适合于作为内部用户行为分析的主id,来标识用户,替代OpenUDID。
注意:如果用户将属于此Vender的所有App卸载,则idfv的值会被重置,即再重装此Vender的App,idfv的值和之前不同。
iphone的一些其他硬件信息:
若要了解iPhone5、6等具体信息需要用到如下代码
//获得设备型号
+ (NSString*)getCurrentDeviceModel:(UIViewController*)controller
{
intmib[2];
size_tlen;
char*machine;
mib[0] = CTL_HW;
mib[1] = HW_MACHINE;
sysctl(mib, 2, NULL,&len, NULL, 0);
machine = malloc(len);
sysctl(mib, 2, machine, &len, NULL, 0);
NSString*platform = [NSStringstringWithCString:machine encoding:NSASCIIStringEncoding];
free(machine);
if([platform isEqualToString:@"iPhone1,1"])return @"iPhone2G (A1203)";
if ([platformisEqualToString:@"iPhone1,2"]) return @"iPhone 3G(A1241/A1324)";
if([platform isEqualToString:@"iPhone2,1"])return @"iPhone3GS (A1303/A1325)";
if([platform isEqualToString:@"iPhone3,1"])return @"iPhone4 (A1332)";
if([platform isEqualToString:@"iPhone3,2"])return @"iPhone4 (A1332)";
if([platform isEqualToString:@"iPhone3,3"])return @"iPhone4 (A1349)";
if([platform isEqualToString:@"iPhone4,1"])return @"iPhone4S (A1387/A1431)";
if([platform isEqualToString:@"iPhone5,1"])return @"iPhone5 (A1428)";
if([platform isEqualToString:@"iPhone5,2"])return @"iPhone5 (A1429/A1442)";
if([platform isEqualToString:@"iPhone5,3"])return @"iPhone5c (A1456/A1532)";
if([platform isEqualToString:@"iPhone5,4"])return @"iPhone5c (A1507/A1516/A1526/A1529)";
if([platform isEqualToString:@"iPhone6,1"])return @"iPhone5s (A1453/A1533)";
if([platform isEqualToString:@"iPhone6,2"])return @"iPhone5s (A1457/A1518/A1528/A1530)";
if([platform isEqualToString:@"iPhone7,1"])return @"iPhone6 Plus (A1522/A1524)";
if([platform isEqualToString:@"iPhone7,2"])return @"iPhone6 (A1549/A1586)";
if([platform isEqualToString:@"iPod1,1"]) return @"iPodTouch 1G (A1213)";
if([platform isEqualToString:@"iPod2,1"]) return @"iPodTouch 2G (A1288)";
if([platform isEqualToString:@"iPod3,1"]) return @"iPodTouch 3G (A1318)";
if([platform isEqualToString:@"iPod4,1"]) return @"iPodTouch 4G (A1367)";
if([platform isEqualToString:@"iPod5,1"]) return @"iPodTouch 5G (A1421/A1509)";
if([platform isEqualToString:@"iPad1,1"]) return @"iPad1G (A1219/A1337)";
if([platform isEqualToString:@"iPad2,1"]) return @"iPad2 (A1395)";
if([platform isEqualToString:@"iPad2,2"]) return @"iPad2 (A1396)";
if([platform isEqualToString:@"iPad2,3"]) return @"iPad2 (A1397)";
if([platform isEqualToString:@"iPad2,4"]) return @"iPad2 (A1395+New Chip)";
if([platform isEqualToString:@"iPad2,5"]) return @"iPadMini 1G (A1432)";
if([platform isEqualToString:@"iPad2,6"]) return @"iPadMini 1G (A1454)";
if([platform isEqualToString:@"iPad2,7"]) return @"iPadMini 1G (A1455)";
if([platform isEqualToString:@"iPad3,1"]) return @"iPad3 (A1416)";
if([platform isEqualToString:@"iPad3,2"]) return @"iPad3 (A1403)";
if([platform isEqualToString:@"iPad3,3"]) return @"iPad3 (A1430)";
if([platform isEqualToString:@"iPad3,4"]) return @"iPad4 (A1458)";
if([platform isEqualToString:@"iPad3,5"]) return @"iPad4 (A1459)";
if([platform isEqualToString:@"iPad3,6"]) return @"iPad4 (A1460)";
if([platform isEqualToString:@"iPad4,1"]) return @"iPadAir (A1474)";
if([platform isEqualToString:@"iPad4,2"]) return @"iPadAir (A1475)";
if([platform isEqualToString:@"iPad4,3"]) return @"iPadAir (A1476)";
if([platform isEqualToString:@"iPad4,4"]) return @"iPadMini 2G (A1489)";
if([platform isEqualToString:@"iPad4,5"]) return @"iPadMini 2G (A1490)";
if([platform isEqualToString:@"iPad4,6"]) return @"iPadMini 2G (A1491)";
if([platform isEqualToString:@"i386"]) return @"iPhoneSimulator";
if([platform isEqualToString:@"x86_64"]) return @"iPhoneSimulator";
returnplatform;
}
参考:1. http://www.cnblogs.com/BigPolarBear/p/3359526.html
2. http://www.oschina.net/code/snippet_2247606_39106/