//收集的一些mac信息的获取方法。后续会继续补充,才刚开始。
#import <CoreServices/CoreServices.h>
///mac地址
+(NSString *)macAdress {
kern_return_t kr;
CFMutableDictionaryRef matchDict;
io_iterator_titerator;
io_registry_entry_t entry;
matchDict =IOServiceMatching("IOEthernetInterface");
kr =IOServiceGetMatchingServices(kIOMasterPortDefault, matchDict, &iterator);
NSDictionary*resultInfo =nil;
NSString*macAdressStr=@"";
while((entry =IOIteratorNext(iterator)) !=0)
{
CFMutableDictionaryRef properties=NULL;
kr =IORegistryEntryCreateCFProperties(entry,
&properties,
kCFAllocatorDefault,
kNilOptions);
if(properties)
{
resultInfo = (__bridge_transferNSDictionary*)properties;
NSString*bsdName = [resultInfoobjectForKey:@"BSD Name"];
NSData*macData = [resultInfoobjectForKey:@"IOMACAddress"];
if(!macData)
{
continue;
}
NSMutableString *macAddress = [[NSMutableString alloc] init];
constUInt8*bytes = [macDatabytes];
for(inti=0; i
{
[macAddressappendFormat:@"%02x",*(bytes+i)];
}
//打印Mac地址
if(bsdName && macAddress)
{
NSLog(@"网卡:%@\nMac地址:%@\n",bsdName,macAddress);
macAdressStr=[NSStringstringWithFormat:@"%@_%@",bsdName,macAddress];
}
}
}
IOObjectRelease(iterator);
returnmacAdressStr;
}
///系统版本
+(NSString *)systemVersion {
NSProcessInfo *info=[[NSProcessInfo alloc]init];
NSString *version = info.operatingSystemVersionString;
NSLog(@"systemVersion=%@",version);
/*或者根据operatingSystemVersion的系统版本信息结构体去拼接
NSInteger majorVersion;
NSInteger minorVersion;
NSInteger patchVersion;
*/
returnversion;
}
网友评论