请问一下各位大神。 在不越狱的情况下(不需要提交到appstore),有可能获取到程序的UDID 、Mac 地址、序列号、IMEI等其中的某一个来唯一标识设备吗? 我尝试过一些方法,但都不能获取。Mac地址一获取就返回一个常量。
http://bbs.iosre.com/t/ios7-udid/296
http://bbs.iosre.com/t/ios-7-udid-3/45
有帖子说不越狱的情况下无法获取。 因为app的沙盒机制权限问题,所以无法获取。 那么如果是这样,有什么方法可以永久唯一标识一台iOS设备么?
其他诸如 uuid + 钥匙串 推送token 等都会有变的可能性,而我的需求是 完全不可变。
//序列号#import <dlfcn.h>
#import <mach/port.h>
#import <mach/kern_return.h>
@implementation UIDevice (serialNumber)
-
(NSString *) serialNumber
{
NSString *serialNumber = nil;void *IOKit = dlopen("/System/Library/Frameworks/IOKit.framework/IOKit", RTLD_NOW);
if (IOKit)
{
mach_port_t *kIOMasterPortDefault = dlsym(IOKit, “kIOMasterPortDefault”);
CFMutableDictionaryRef (*IOServiceMatching)(const char *name) = dlsym(IOKit, “IOServiceMatching”);
mach_port_t (*IOServiceGetMatchingService)(mach_port_t masterPort, CFDictionaryRef matching) = dlsym(IOKit, “IOServiceGetMatchingService”);
CFTypeRef (*IORegistryEntryCreateCFProperty)(mach_port_t entry, CFStringRef key, CFAllocatorRef allocator, uint32_t options) = dlsym(IOKit, “IORegistryEntryCreateCFProperty”);
kern_return_t (*IOObjectRelease)(mach_port_t object) = dlsym(IOKit, “IOObjectRelease”);if (kIOMasterPortDefault && IOServiceGetMatchingService && IORegistryEntryCreateCFProperty && IOObjectRelease) { mach_port_t platformExpertDevice = IOServiceGetMatchingService(*kIOMasterPortDefault, IOServiceMatching("IOPlatformExpertDevice")); if (platformExpertDevice) { CFTypeRef platformSerialNumber = IORegistryEntryCreateCFProperty(platformExpertDevice, CFSTR("IOPlatformSerialNumber"), kCFAllocatorDefault, 0); if (CFGetTypeID(platformSerialNumber) == CFStringGetTypeID()) //iOS8 在这一行崩溃 { serialNumber = [NSString stringWithString:(__bridge NSString*)platformSerialNumber]; CFRelease(platformSerialNumber); } IOObjectRelease(platformExpertDevice); } } dlclose(IOKit);
}
return serialNumber;
}