在iPad上获取序列号

时间:2012-09-12 14:04:24

标签: ipad ios5

我想获得iPad的序列号?我找到了两种可以归档的方法,第一种是使用uuid,但这不是最好的解决方案。因为我需要序列号,因为它位于iPad背面。

另一个解决方案是实现一个已弃用的github项目:/

那么检索序列号是不是可以打印在iPad背面?

如果不可能,这是因为序列号以某种方式受到保护,所以我不能错过使用它吗?

[UPDATE] 如果无法获得序列号,那么可以获取设备名称吗?

提前致谢:)

1 个答案:

答案 0 :(得分:0)

可以检索iOS设备的序列号。但我不确定Apple是否允许这些应用程序进入AppStore。

您将需要这些导入:

#import <sys/utsname.h>
#import <dlfcn.h>

以下方法将检索设备序列号

+(NSString *) getSerialNumber
{
    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())
                {
                    serialNumber = [NSString stringWithString:(__bridge NSString*)platformSerialNumber];
                    CFRelease(platformSerialNumber);
                }
                IOObjectRelease(platformExpertDevice);
            }
        }
        dlclose(IOKit);
    }
    return serialNumber;
}

获取设置中配置的设备的名称非常简单。请尝试以下方法。

+(NSString *) getDeviceName
{
    //RETURNS THE DEVICE NAME CONFIGURED IN SETTINGS
    NSString *nameString = [[UIDevice currentDevice] name];
    return nameString;
}