一:在iOS系统中提供了系统版本的判断函数,因此我们可以很容易得到他的当前系统版本:
[[UIDevice currentDevice] systemName];//系统名字
[[UIDevice currentDevice] systemVersion];//系统版本号
[[UIDevice currentDevice] uniqueIdentifier];//
[[UIDevice currentDevice] model]; //设备型号
这些方法都能够帮助你快速得到你所想要的关于系统硬件和软件的相关信息。
二:获取设备串号及相关的信息:
使用IOKit.framework框架来实现,利用第三方库IOKitExtentions来实现
#if SUPPORTS_IOKIT_EXTENSIONS
@interface UIDevice (IOKit_Extensions)
- (NSString *) imei;
- (NSString *) serialnumber;
- (NSString *) backlightlevel;
@end
#endif
#import "UIDevice-IOKitExtensions.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 propID = (CFTypeID) NULL;
unsigned int bufSize;
kern_return_t kr = IOMasterPort(MACH_PORT_NULL, &masterPort);
if (kr != noErr) return nil;
io_registry_entry_t entry = IORegistryGetRootEntry(masterPort);
if (entry == MACH_PORT_NULL) return nil;
CFTypeRef prop = IORegistryEntrySearchCFProperty(entry, kIODeviceTreePlane, (CFStringRef) iosearch, nil, kIORegistryIterateRecursively);
if (!prop) return nil;
propID = CFGetTypeID(prop);
if (!(propID == CFDataGetTypeID()))
{
mach_port_deallocate(mach_task_self(), masterPort);
return nil;
}
CFDataRef propData = (CFDataRef) prop;
if (!propData) return nil;
bufSize = CFDataGetLength(propData);
if (!bufSize) return nil;
NSString *p1 = [[[NSString alloc] initWithBytes:CFDataGetBytePtr(propData) length:bufSize encoding:1] autorelease];
mach_port_deallocate(mach_task_self(), masterPort);
return [p1 componentsSeparatedByString:@"\0"];
}
- (NSString *) imei
{
NSArray *results = getValue(@"device-imei");
if (results) return [results objectAtIndex:0];
return nil;
}
- (NSString *) serialnumber
{
NSArray *results = getValue(@"serial-number");
if (results) return [results objectAtIndex:0];
return nil;
}
- (NSString *) backlightlevel
{
NSArray *results = getValue(@"backlight-level");
if (results) return [results objectAtIndex:0];
return nil;
}
@end
#endif
在工程中加入IOKit这个文件的时候,会报错误xcode5 ios7 framework not found IOKit
此时进行如下操作:
cd /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.0.sdk/System/Library/Frameworks/IOKit.framework
sudo ln -s Versions/A/IOKit