本記事は「デバイスのシリアル番号を取得する - iOSアプリ開発の逆引き辞典」に転記しました。
ちょっとシリアル番号が取得出来るかどうかを調査してみました。結論から言うとシリアル番号を取得する事は出来ましたが、これがundocumentな使い方かどうかが判らないや。
// // UIDevice+Softbuild.h // libraryreference // // Created by Wada Kenji on 10/12/04. // Copyright 2010 Softbuild. All rights reserved. // #import <UIKit/UIDevice.h> @interface UIDevice (Softbuild) @property (nonatomic, readonly) NSString *serialNumber; @end
// // UIDevice+Softbuild.m // libraryreference // // Created by Wada Kenji on 10/12/04. // Copyright 2010 Softbuild. All rights reserved. // #import "UIDevice+Softbuild.h" #import <dlfcn.h> #import <mach/port.h> #import <mach/kern_return.h> @implementation UIDevice (Softbuild) - (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()) { serialNumber = [NSString stringWithString:(NSString*)platformSerialNumber]; CFRelease(platformSerialNumber); } IOObjectRelease(platformExpertDevice); } } dlclose(IOKit); } return serialNumber; } @end