1.获取设备的信息
UIDevice *device = [[UIDevice alloc] init];
NSString *name = device.name; //获取设备所有者的名称
NSString *model = device.name; //获取设备的类别
NSString *type = device.localizedModel; //获取本地化版本
NSString *systemName = device.systemName; //获取当前运行的系统
NSString *systemVersion = device.systemVersion;//获取当前系统的版本
NSLog(@"name:%@\nmodel:%@\ntype:%@\nsystemName:%@\nsystemVersion:%@\n",name,model,type,systemName,systemVersion);
2.获取设备的唯一标示符
NSString *identifier = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
NSLog(@"identifier:%@",identifier);
3.创建一个uuid(一个随机的标示符)
NSString *uuid = [self createUUID];
NSLog(@"uuid:%@",uuid);
- (NSString*)createUUID {
NSString *id = [[NSUserDefaults standardUserDefaults] objectForKey:@"UUID"]; //获取标识为"UUID"的值
if(id == nil)
{
if([[[UIDevice currentDevice] systemVersion] floatValue] > 6.0)
{
//ios 6.0 之后可以使用的api
NSString *identifierNumber = [[NSUUID UUID] UUIDString];
[[NSUserDefaults standardUserDefaults] setObject:identifierNumber forKey:@"UUID"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
else{
//ios6.0之前使用的api
CFUUIDRef uuid = CFUUIDCreate(NULL);
CFStringRef uuidString = CFUUIDCreateString(NULL, uuid);
NSString *identifierNumber = [NSString stringWithFormat:@"%@", uuidString];
[[NSUserDefaults standardUserDefaults] setObject:identifierNumber forKey:@"UUID"];
[[NSUserDefaults standardUserDefaults] synchronize];
CFRelease(uuidString);
CFRelease(uuid);
}
return [[NSUserDefaults standardUserDefaults] objectForKey:@"UUID"];
}
return id;
}