iOS获取OpenUUID
来源:互联网 发布:软件质量控制流程 编辑:程序博客网 时间:2024/05/21 17:00
#pragma mark - 获取MAC地址+ (NSString *)obtainMacAddress { int mib[6]; size_t len; char *buf; unsigned char *ptr; struct if_msghdr *ifm; struct sockaddr_dl *sdl; mib[0] = CTL_NET; mib[1] = AF_ROUTE; mib[2] = 0; mib[3] = AF_LINK; mib[4] = NET_RT_IFLIST; if ((mib[5] = if_nametoindex("en0")) == 0) { printf("Error: if_nametoindex error\n"); return NULL; } if (sysctl(mib, 6, NULL, &len, NULL, 0) < 0) { printf("Error: sysctl, take 1\n"); return NULL; } if ((buf = malloc(len)) == NULL) { printf("Could not allocate memory. error!\n"); return NULL; } if (sysctl(mib, 6, buf, &len, NULL, 0) > 0) { free(buf); printf("Error: sysctl, take 2"); return NULL; } ifm = (struct if_msghdr *)buf; sdl = (struct sockaddr_dl *)(ifm + 1); ptr = (unsigned char *)LLADDR(sdl); NSString *outstring = [NSString stringWithFormat:@"%02x%02x%02x%02x%02x%02x", *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4), *(ptr+5)]; free(buf); return [outstring uppercaseString];}
#pragma mark - 获取设备UUID- (void)obtainDeviceOpenUUID { if (![kUserDefaults objectForKey:kOpenUUIDKey]) { NSString *uuid = nil; if ([[[UIDevice currentDevice] systemVersion] floatValue] < 6.0) { uuid = [NSString obtainMacAddress]; // 6.0以前用MAC地址作为UID } else { // identifierForVendor 6.0后可用 uuid = [[[UIDevice currentDevice] identifierForVendor] UUIDString]; } [kUserDefaults setObject:uuid forKey:kOpenUUIDKey]; } return;}
0 0
- iOS获取OpenUUID
- iOS 获取磁盘,获取文件大小
- ios 获取ios系统信息
- iOS 获取DOCUMENT目录
- 获取IOS设备字体
- 获取IOS App版本
- ios获取系统时间
- ios获取日期间隔
- IOS获取屏幕分辨率
- IOS 获取农历方法
- IOS获取屏幕分辨率
- ios 获取各路径
- ios获取当前经纬度
- iOS获取常用目录
- iOS获取应用列表
- 获取iOS设备类型
- 获取IOS版本
- IOS获取屏幕分辨率
- 剑指offer面试题21
- 怎样快速学习一门新技术
- 探讨C++中对象的“浅拷贝”与“深拷贝”
- 怎样快速学习一门新技术
- Z**002
- iOS获取OpenUUID
- 剑指offer面试题22
- 15-1-(1)-工资数据的输入(cin)
- 打造良好UI的32条建议(上)
- 打造良好UI的32条建议(下)
- Z**0022B
- cocos2d_android 向布景层添加一个精灵对象
- iOS开发中常用的两种架构(1)
- 就这样被你破坏