Hi I am new to Objective C. Please help me how to get the device serial number in iPhone please help me anyone please provide a sample application.
Thanks in advance.
Hi I am new to Objective C. Please help me how to get the device serial number in iPhone please help me anyone please provide a sample application.
Thanks in advance.
For iOS:
Apple does not allow developers to access a device serial number on iOS. Alternatively, they provide you with identifierForVendor
:
An alphanumeric string that uniquely identifies a device to the app’s vendor. (read-only)
For macOS:
var serialNumber: String? {
let platformExpert = IOServiceGetMatchingService(kIOMasterPortDefault, IOServiceMatching("IOPlatformExpertDevice") )
guard platformExpert > 0 else {
return nil
}
guard let serialNumber = (IORegistryEntryCreateCFProperty(platformExpert, kIOPlatformSerialNumberKey as CFString, kCFAllocatorDefault, 0).takeUnretainedValue() as? String)?.trimmingCharacters(in: CharacterSet.whitespacesAndNewlines) else {
return nil
}
IOObjectRelease(platformExpert)
return serialNumber
}
Source: https://gist.github.com/leogdion/77f6143ecf793e1ba381917d4b3b286c