在iOS中,libMobileGestalt动态库, 用来取得各种系统变量,比如UDID, 磁盘使用量, 设备版本

在iOS7中,对于开发者来说,一个头痛的问题是:UIDI完全是失效了
从iOS5开始,Apple就禁止程序获得设备的UDID
在iOS6中, 可以用 [[UIDevice currentDevice] uniqueIdentifier] 来获取

在Cydia中,可以获取

http://gitweb.saurik.com/cydia.git/blob/90bf9a3d170ab2dc4701c76f7b3911308211f542:/MobileCydia.mm

static CFStringRef (*$MGCopyAnswer)(CFStringRef);

void *gestalt(dlopen(“/usr/lib/libMobileGestalt.dylib”, RTLDGLOBAL | RTLDLAZY));
$MGCopyAnswer = reinterpret_cast(dlsym(gestalt, “MGCopyAnswer”));

(id)$MGCopyAnswer(CFSTR(“UniqueDeviceID”));

http://hiraku.tw/2013/12/3316/

#import "UIDevice+MobileGestaltCategroy.h"

@implementation UIDevice (MobileGestalt)

// Mobile Gestalt EquipmentInfo
extern CFTypeRef MGCopyAnswer(CFStringRef);

- (NSString *)UDID {
    NSString *retVal = nil;
    CFTypeRef tmp = MGCopyAnswer(CFSTR("UniqueDeviceID"));
    if (tmp) {
        retVal = [NSString stringWithString:tmp];
        CFRelease(tmp);
    }
    return retVal;
}

- (NSString *)IMEI {
    NSString *retVal = nil;
    CFTypeRef tmp = MGCopyAnswer(CFSTR("InternationalMobileEquipmentIdentity"));
    if (tmp) {
        retVal = [NSString stringWithString:tmp];
        CFRelease(tmp);
    }
    return retVal;
}

- (NSString *)ICCID {
    NSString *retVal = nil;
    CFArrayRef infoArray = MGCopyAnswer(CFSTR("CarrierBundleInfoArray"));
    if (infoArray) {
        CFDictionaryRef infoDic = CFArrayGetValueAtIndex(infoArray, 0);
        if (infoDic) {
            retVal = [NSString stringWithString:CFDictionaryGetValue(infoDic, CFSTR("IntegratedCircuitCardIdentity"))];
        }
        CFRelease(infoArray);
    }
    return retVal;
}

- (NSString *)serialNumber {
    NSString *retVal = nil;
    CFTypeRef tmp = MGCopyAnswer(CFSTR("SerialNumber"));
    if (tmp) {
        retVal = [NSString stringWithString:tmp];
        CFRelease(tmp);
    }
    return retVal;
}

- (NSString *)wifiAddress {
    NSString *retVal = nil;
    CFTypeRef tmp = MGCopyAnswer(CFSTR("WifiAddress"));
    if (tmp) {
        retVal = [NSString stringWithString:tmp];
        CFRelease(tmp);
    }
    return retVal;
}

- (NSString *)bluetoothAddress {
    NSString *retVal = nil;
    CFTypeRef tmp = MGCopyAnswer(CFSTR("BluetoothAddress"));
    if (tmp) {
        retVal = [NSString stringWithString:tmp];
        CFRelease(tmp);
    }
    return retVal;
}

- (NSString *)cpuArchitecture {
    NSString *retVal = nil;
    CFTypeRef tmp = MGCopyAnswer(CFSTR("CPUArchitecture"));
    if (tmp) {
        retVal = [NSString stringWithString:tmp];
        CFRelease(tmp);
    }
    return retVal;
}

- (NSString *)productType {
    NSString *retVal = nil;
    CFTypeRef tmp = MGCopyAnswer(CFSTR("ProductType"));
    if (tmp) {
        retVal = [NSString stringWithString:tmp];
        CFRelease(tmp);
    }
    return retVal;
}

- (BOOL)airplaneMode {
    BOOL retVal = NO;
    CFTypeRef tmp = MGCopyAnswer(CFSTR("AirplaneMode"));
    if (tmp) {
        if (tmp == kCFBooleanTrue) {
            retVal = YES;
        }
        CFRelease(tmp);
    }
    return retVal;
}

@end