• xcode获取mac address


    1,首先下载GetPrimaryMACAddress.c:http://files.cnblogs.com/files/MartinLi841538513/GetPrimaryMACAddress.c.zip

    2,然后设置GetPrimaryMACAddress.c的Type为Objective-C Source,否则会出现头文件互相引用问题。

    3,在你想要获取addres的地方,#include "GetPrimaryMACAddress.c"

    并调用:

    -(NSString *)macAddress{
        NSMutableString *macAddress = [NSMutableString new];
        kern_return_t    kernResult = KERN_SUCCESS;
        io_iterator_t    intfIterator;
        UInt8            MACAddress[kIOEthernetAddressSize];
        
        kernResult = FindEthernetInterfaces(&intfIterator);
        
        if (KERN_SUCCESS != kernResult) {
            printf("FindEthernetInterfaces returned 0x%08x
    ", kernResult);
        }
        else {
            kernResult = GetMACAddress(intfIterator, MACAddress, sizeof(MACAddress));
            
            if (KERN_SUCCESS != kernResult) {
                printf("GetMACAddress returned 0x%08x
    ", kernResult);
            }
            else {
                printf("This system's built-in MAC address is %02x:%02x:%02x:%02x:%02x:%02x.
    ",
                       MACAddress[0], MACAddress[1], MACAddress[2], MACAddress[3], MACAddress[4], MACAddress[5]);
            }
        }
        
        (void) IOObjectRelease(intfIterator);    // Release the iterator.
        [macAddress appendFormat:@"%hhu:",MACAddress[0]];
        [macAddress appendFormat:@"%hhu:",MACAddress[1]];
        [macAddress appendFormat:@"%hhu:",MACAddress[2]];
        [macAddress appendFormat:@"%hhu:",MACAddress[3]];
        [macAddress appendFormat:@"%hhu:",MACAddress[4]];
        [macAddress appendFormat:@"%hhu",MACAddress[5]];
        return macAddress;
    }

    然后,就会出来类似这样的macAddress:128:230:80:30:10:204 地址

  • 相关阅读:
    redis中的发布订阅(Pub/Sub)
    emmc基础技术8:操作模式3-interrupt mode
    Linux命令-tar
    git获取内核源码的方法
    Linux内核基础设施
    Linux内核简介
    emmc基础技术8:操作模式2-device identification mode
    内核子系统文档撰写方法
    eMMC基础技术6:eMMC data读写
    eMMC基础技术10:寄存器介绍
  • 原文地址:https://www.cnblogs.com/MartinLi841538513/p/4521750.html
Copyright © 2020-2023  润新知