Search code examples
iosuname

What is utsname and systemInfo?


When I found way to get iOS device type (e.g., iPhone 6, iPhone 6 Plus), I found a way to do and it did help

but it give me this two question?

  1. What is utsname and systemInfo, why we can get the device type through it?
  2. Why need the convert like this?

    ^ @"iPhone5,4" :@"iPhone 5c",       // (model A1507, A1516, A1526 (China), A1529 | Global)
    @"iPhone6,1" :@"iPhone 5s",       // (model A1433, A1533 | GSM)
    @"iPhone6,2" :@"iPhone 5s",  
    

Solution

    1. POSIX defines struct utsname as the structure returned by the uname function. The uname function returns information about the current system.

      The identifier systemInfo is just a variable name. It has no special meaning.

    2. The “need to convert” exists because utsname.machine contains a string intended for programs, programmers and technicians, not end users. There have been multiple hardware versions of certain devices, like the iPhone 5S. Apple calls all of them “iPhone 5S” when speaking to users. Internally, you can tell which hardware version you're on by looking at the utsname.machine string. If you want to refer to the user's device by its user-friendly name, you need to convert from the utsname.machine string to the user-friendly name.