上篇博文提到了ios 还可以通过其他方法获得更多的硬件信息,例如mac地址,电池电量,序列号,IMIE,总磁盘大小,背光等等,现贴出我已经测试通过的程序,获取IMIE,mac地址和序列号。
首先,引入libIOkit 的两个库文件,然后可以创建UIDevice 的catagroy。
具体代码如下:
#import "network.h"
#include <sys/types.h>
#include <sys/sysctl.h>
#import <mach/mach_host.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <ifaddrs.h>
#include <sys/socket.h>
#include <net/if.h>
#include <net/if_dl.h>
#include <ifaddrs.h>
#if SUPPORTS_IOKIT_EXTENSIONS
#pragma mark IOKit miniheaders
#define kIODeviceTreePlane "IODeviceTree"
enum {
kIORegistryIterateRecursively = 0x00000001,
kIORegistryIterateParents = 0x00000002
};
typedef mach_port_t io_object_t;
typedef io_object_t io_registry_entry_t;
typedef char io_name_t[128];
typedef UInt32 IOOptionBits;
CFTypeRef
IORegistryEntrySearchCFProperty(
io_registry_entry_t entry,
const io_name_t plane,
CFStringRef key,
CFAllocatorRef allocator,
IOOptionBits options );
kern_return_t
IOMasterPort( mach_port_t bootstrapPort,
mach_port_t * masterPort );
io_registry_entry_t
IORegistryGetRootEntry(
mach_port_t masterPort );
CFTypeRef
IORegistryEntrySearchCFProperty(
io_registry_entry_t entry,
const io_name_t plane,
CFStringRef key,
CFAllocatorRef allocator,
IOOptionBits options );
kern_return_t mach_port_deallocate
(ipc_space_t task,
mach_port_name_t name);
@implementation UIDevice (IOKit_Extensions)
#pragma mark IOKit Utils
NSArray *getValue(NSString *iosearch)
{
mach_port_t masterPort;
CFTypeID pr