概要
- Swiftで下記に記載されているシリアル番号とハードウェアUUIDを取得する
実装
func loadIOPlatformExpertDevice(ioService: String, propertyKey: String) -> String? {
let service = IOServiceGetMatchingService(kIOMainPortDefault, IOServiceMatching(ioService))
if service <= 0 {
return nil
}
guard let _property = IORegistryEntryCreateCFProperty(service, propertyKey as CFString, kCFAllocatorDefault, 0),
let property = _property.takeUnretainedValue() as? String
else {
return nil
}
IOObjectRelease(service)
return property
}
let keys = [
kIOPlatformSerialNumberKey,
kIOPlatformUUIDKey,
]
keys.forEach { key in
if let value = loadIOPlatformExpertDevice(ioService: "IOPlatformExpertDevice", propertyKey: key) {
print(value)
}
}
参考
UDIDの使用が禁止される理由
広告業者(モバイル広告提供者)がこのUDIDを使って、特定の利用者(UDID)がどのような広告にアクセスし、どんなアプリを使ったり買ったりしているかという個人情報を取得できます。そして、利用者がこれを防ぐ手段がないのでプライバシーの侵害に繋がると米国議会から非難されたからです。
Macアドレスはだめ
ioreg -d2 -c IOPlatformExpertDevice | awk -F\" '/IOPlatformUUID/{print $(NF-1)}'
他の情報