The collection of device information is divided into two parts. The first is of course some private and unique information of the device, and the second is the information of App. Let’s start with simple App information.

The first part: App information

For App information, we probably need to get the App version number, App build version number, package name, App display name and so on.

#pragma mark - About App Config Info Method */ + (NSString *)getAppVersion {NSBundle *currentBundle = [NSBundle mainBundle]; NSDictionary *infoDictionary = [currentBundle infoDictionary]; return [infoDictionary objectForKey:@"CFBundleShortVersionString"]; } /* getAppBuildVersion {NSBundle *currentBundle = [NSBundle mainBundle]; / / getAppBuildVersion {NSBundle *currentBundle = [NSBundle mainBundle]; NSDictionary *infoDictionary = [currentBundle infoDictionary]; return [infoDictionary objectForKey:@"CFBundleVersion"]; } /* getAppBundleId {NSBundle *currentBundle = [NSBundle mainBundle]; NSDictionary *infoDictionary = [currentBundle infoDictionary]; return [infoDictionary objectForKey:@"CFBundleIdentifier"]; } /* Get the current App name information */ + (NSString *)getAppDisplayName {NSBundle *currentBundle = [NSBundle mainBundle]; NSDictionary *infoDictionary = [currentBundle infoDictionary]; return [infoDictionary objectForKey:@"CFBundleDisplayName"]; }Copy the code

Part TWO: Some private and unique information about the device

About obtaining various identifiers of devices, the general statistics. Basically there are IDFA, IDFV, IMEI, IMSI, UUID, UDID, MAC address and so on. However, with the protection of user privacy information, The Apple system sets the permission to obtain information, such as IMEI, IMSI, etc., are explicitly prohibited, unless your App is not released through the Channel of Apple Store. Regardless of the permissions, let’s first explain what these fields mean.

1. IMEI, IMSI, UUID, UDID, MAC address IMEI: International Mobile Equipment Identity International Mobile Equipment Identity is a 15-digit electronic serial number that corresponds to each Mobile phone and is unique in the world. Once assembled, each phone will be assigned a globally unique set of numbers, which will be recorded by the manufacturer from production to delivery. Mobile phone users can check their mobile phone’s IMEI code. Due to privacy issues, apple users will no longer be able to obtain IMEI values after iOS5. If your App is not listed in Apple Store and you want to obtain the IMEI value, you can refer to this link to obtain the IMEI value.

IMSI: International Mobile Subscriber Identification Number, short for International Mobile Subscriber Identification Number, is divided into two parts: Part of the MCC is called Mobile Country Code (MCC). The RESOURCES of MCC are uniformly allocated by the International Telecommunication Union (ITU), and the MCC uniquely identifies the Country to which the Mobile user belongs. The MCC has three digits, and the MCC in China is 460. The other part is called Mobile Network Code (MNC), which identifies the Mobile Network operator to which a Mobile customer belongs. The MNC consists of two to three decimal digits. For example, the MNC of China Mobile is 00, 02, and 07; the MNC of China Unicom is 01, 06, and 09; and the MNC of China Telecom is 03, 05, and 11.

Universally Unique Identifier UUID: Universally Unique Identifier A UUID is a number generated on a machine that is guaranteed to be unique to all machines in the same space and time. Typically the platform provides the generated API, which is a 32-bit hexadecimal sequence connected by small horizontal lines: 8-4-4-12. By its very nature, UUID is guaranteed to be unique to all machines in the same space and time. So, if you want unique identifiers, you can store them in keychain or in NSUserDefaults.

UDID: A UDID is a unique device identifier used by mobile advertisers and game network operators to identify users and track user activity. UDID was deprecated in iOS5.0. Because of privacy concerns, apple announced that if third-party app developers continue to share or use the UDID for the iPhone, Mac, or AppleWatch, their apps will be banned. For example, I developed five apps, and many users downloaded these five apps and used them. If I can easily get the UDID of these users, I can actually piece together a lot of information about them. Due to its privacy nature, UDID was often used for third-party statistics and other purposes. Apple has introduced an alternative to the UDID, the identifierForVendor attribute, more on IDFV in the next section. The UDID is mainly used to configure the real machine debugging certificate.

MAC Address: THE MAC address is unique. Unix has system calls to obtain the MAC address. An iPhone can have multiple Mac addresses, wifi addresses, and SIM card addresses. Generally speaking, we take the address of EN0, because it is the wifi address of iPhone, it certainly exists (exception still exists: there are still some Castrated version of unicom iPhone without wifi on the market). Mac addresses are private and should not be spread randomly. Therefore, we need to hash Mac addresses before using them. Also due to privacy issues, after iOS7, apple prohibited obtaining MAC addresses. The system now only returns virtual addresses of 02:00:00.00:00:00:00.

2, IDFA, IDFV IDFA: advertising identifier, iOS6 and later use. The user can control whether or not the IDFA is allowed to be fetched and reset in the Settings, although the average user is not aware of this permission setting, so the IDFA should not be used as a substitute for a device unique identifier (UUID).

Close IDFA access operation: Settings → Privacy → Advertising → Select Prohibit IDFA value to regenerate IDFA operation: Operation 1: Set program → General → Restore → Restore location and privacy Operation 2: Set program → General → About the machine → Advertising → restore advertising identifier

Obtain UUID: NSString * IDfV = [[[UIDevice currentDevice] identifierForVendor] UUIDString]; Obtaining a MAC Address

In development, we often need to obtain the model of the device (such as iPhone X, iPhone 8 Plus, etc.) for data statistics, or to make different adaptions. But Apple doesn’t provide a system API that lets us directly access the current device model. UIDevice has a property model that is only used to get the type of iOS devices, such as iPhone, iPod Touch, iPad, etc. The other attribute name represents the name of the current device, which can be set by the user in the name of Settings “General” about, such as My iPhone, iPhone of XXX, etc. However, we can’t get a specific model based on these two values. However, each iOS device model has one or more hardware codes/identifiers, called device Model or Machine Name, which can be obtained by code as described in the previous episode:

 // 需要#import "sys/utsname.h"
+ (NSString *)getDeviceIdentifier {
    struct utsname systemInfo;
    uname(&systemInfo);
    // 获取设备标识Identifier
    NSString *platform = [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];
    
    // iPhone
    if ([platform isEqualToString:@"iPhone1,1"]) return @"iPhone 2G";
    if ([platform isEqualToString:@"iPhone1,2"]) return @"iPhone 3G";
    if ([platform isEqualToString:@"iPhone2,1"]) return @"iPhone 3GS";
    if ([platform isEqualToString:@"iPhone3,1"]) return @"iPhone 4";
    if ([platform isEqualToString:@"iPhone3,2"]) return @"iPhone 4";
    if ([platform isEqualToString:@"iPhone3,3"]) return @"iPhone 4";
    if ([platform isEqualToString:@"iPhone4,1"]) return @"iPhone 4S";
    if ([platform isEqualToString:@"iPhone5,1"]) return @"iPhone 5";
    if ([platform isEqualToString:@"iPhone5,2"]) return @"iPhone 5";
    if ([platform isEqualToString:@"iPhone5,3"]) return @"iPhone 5c";
    if ([platform isEqualToString:@"iPhone5,4"]) return @"iPhone 5c";
    if ([platform isEqualToString:@"iPhone6,1"]) return @"iPhone 5s";
    if ([platform isEqualToString:@"iPhone6,2"]) return @"iPhone 5s";
    if ([platform isEqualToString:@"iPhone7,1"]) return @"iPhone 6 Plus";
    if ([platform isEqualToString:@"iPhone7,2"]) return @"iPhone 6";
    if ([platform isEqualToString:@"iPhone8,1"]) return @"iPhone 6s";
    if ([platform isEqualToString:@"iPhone8,2"]) return @"iPhone 6s Plus";
    if ([platform isEqualToString:@"iPhone8,4"]) return @"iPhone SE";
    if ([platform isEqualToString:@"iPhone9,1"]) return @"iPhone 7";
    if ([platform isEqualToString:@"iPhone9,2"]) return @"iPhone 7 Plus";
    if ([platform isEqualToString:@"iPhone10,1"]) return @"iPhone 8";
    if ([platform isEqualToString:@"iPhone10,4"]) return @"iPhone 8";
    if ([platform isEqualToString:@"iPhone10,2"]) return @"iPhone 8 Plus";
    if ([platform isEqualToString:@"iPhone10,5"]) return @"iPhone 8 Plus";
    if ([platform isEqualToString:@"iPhone10,3"]) return @"iPhone X";
    if ([platform isEqualToString:@"iPhone10,6"]) return @"iPhone X";
    if ([platform isEqualToString:@"iPhone11,2"]) return @"iPhone XS";
    if ([platform isEqualToString:@"iPhone11,6"]) return @"iPhone XS MAX";
    if ([platform isEqualToString:@"iPhone11,8"]) return @"iPhone XR";
    if ([platform isEqualToString:@"iPhone12,1"]) return @"iPhone 11";
    if ([platform isEqualToString:@"iPhone12,3"]) return @"iPhone 11 Pro";
    if ([platform isEqualToString:@"iPhone12,5"]) return @"iPhone 11 Pro Max";
    if ([platform isEqualToString:@"iPhone12,8"]) return @"iPhone SE (2nd generation)";
    if ([platform isEqualToString:@"iPhone13,1"]) return @"iPhone 12 mini";
    if ([platform isEqualToString:@"iPhone13,2"]) return @"iPhone 12";
    if ([platform isEqualToString:@"iPhone13,3"]) return @"iPhone 12 Pro";
    if ([platform isEqualToString:@"iPhone13,4"]) return @"iPhone 12 Pro Max";
    
    
    // iPod
    if ([platform isEqualToString:@"iPod1,1"])  return @"iPod Touch 1";
    if ([platform isEqualToString:@"iPod2,1"])  return @"iPod Touch 2";
    if ([platform isEqualToString:@"iPod3,1"])  return @"iPod Touch 3";
    if ([platform isEqualToString:@"iPod4,1"])  return @"iPod Touch 4";
    if ([platform isEqualToString:@"iPod5,1"])  return @"iPod Touch 5";
    if ([platform isEqualToString:@"iPod7,1"])  return @"iPod Touch 6";
    if ([platform isEqualToString:@"iPod9,1"])  return @"iPod Touch 7";
    
    // iPad
    if ([platform isEqualToString:@"iPad1,1"])  return @"iPad 1";
    if ([platform isEqualToString:@"iPad2,1"])  return @"iPad 2";
    if ([platform isEqualToString:@"iPad2,2"]) return @"iPad 2";
    if ([platform isEqualToString:@"iPad2,3"])  return @"iPad 2";
    if ([platform isEqualToString:@"iPad2,4"])  return @"iPad 2";
    if ([platform isEqualToString:@"iPad2,5"])  return @"iPad Mini 1";
    if ([platform isEqualToString:@"iPad2,6"])  return @"iPad Mini 1";
    if ([platform isEqualToString:@"iPad2,7"])  return @"iPad Mini 1";
    if ([platform isEqualToString:@"iPad3,1"])  return @"iPad 3";
    if ([platform isEqualToString:@"iPad3,2"])  return @"iPad 3";
    if ([platform isEqualToString:@"iPad3,3"])  return @"iPad 3";
    if ([platform isEqualToString:@"iPad3,4"])  return @"iPad 4";
    if ([platform isEqualToString:@"iPad3,5"])  return @"iPad 4";
    if ([platform isEqualToString:@"iPad3,6"])  return @"iPad 4";
    if ([platform isEqualToString:@"iPad4,1"])  return @"iPad Air";
    if ([platform isEqualToString:@"iPad4,2"])  return @"iPad Air";
    if ([platform isEqualToString:@"iPad4,3"])  return @"iPad Air";
    if ([platform isEqualToString:@"iPad4,4"])  return @"iPad Mini 2";
    if ([platform isEqualToString:@"iPad4,5"])  return @"iPad Mini 2";
    if ([platform isEqualToString:@"iPad4,6"])  return @"iPad Mini 2";
    if ([platform isEqualToString:@"iPad4,7"])  return @"iPad mini 3";
    if ([platform isEqualToString:@"iPad4,8"])  return @"iPad mini 3";
    if ([platform isEqualToString:@"iPad4,9"])  return @"iPad mini 3";
    if ([platform isEqualToString:@"iPad5,1"])  return @"iPad mini 4";
    if ([platform isEqualToString:@"iPad5,2"])  return @"iPad mini 4";
    if ([platform isEqualToString:@"iPad5,3"])  return @"iPad Air 2";
    if ([platform isEqualToString:@"iPad5,4"])  return @"iPad Air 2";
    if ([platform isEqualToString:@"iPad6,3"])  return @"iPad Pro (9.7-inch)";
    if ([platform isEqualToString:@"iPad6,4"])  return @"iPad Pro (9.7-inch)";
    if ([platform isEqualToString:@"iPad6,7"])  return @"iPad Pro (12.9-inch)";
    if ([platform isEqualToString:@"iPad6,8"])  return @"iPad Pro (12.9-inch)";
    if ([platform isEqualToString:@"iPad6,11"])  return @"iPad 5";
    if ([platform isEqualToString:@"iPad6,12"])  return @"iPad 5";
    if ([platform isEqualToString:@"iPad7,1"])  return @"iPad Pro 2(12.9-inch)";
    if ([platform isEqualToString:@"iPad7,2"])  return @"iPad Pro 2(12.9-inch)";
    if ([platform isEqualToString:@"iPad7,3"])  return @"iPad Pro (10.5-inch)";
    if ([platform isEqualToString:@"iPad7,4"])  return @"iPad Pro (10.5-inch)";
    if ([platform isEqualToString:@"iPad7,5"])  return @"iPad 6";
    if ([platform isEqualToString:@"iPad7,6"])  return @"iPad 6";
    if ([platform isEqualToString:@"iPad7,11"])  return @"iPad 7";
    if ([platform isEqualToString:@"iPad7,12"])  return @"iPad 7";
    if ([platform isEqualToString:@"iPad8,1"])  return @"iPad Pro (11-inch) ";
    if ([platform isEqualToString:@"iPad8,2"])  return @"iPad Pro (11-inch) ";
    if ([platform isEqualToString:@"iPad8,3"])  return @"iPad Pro (11-inch) ";
    if ([platform isEqualToString:@"iPad8,4"])  return @"iPad Pro (11-inch) ";
    if ([platform isEqualToString:@"iPad8,5"])  return @"iPad Pro 3 (12.9-inch) ";
    if ([platform isEqualToString:@"iPad8,6"])  return @"iPad Pro 3 (12.9-inch) ";
    if ([platform isEqualToString:@"iPad8,7"])  return @"iPad Pro 3 (12.9-inch) ";
    if ([platform isEqualToString:@"iPad8,8"])  return @"iPad Pro 3 (12.9-inch) ";
    if ([platform isEqualToString:@"iPad11,1"])  return @"iPad mini 5";
    if ([platform isEqualToString:@"iPad11,2"])  return @"iPad mini 5";
    if ([platform isEqualToString:@"iPad11,3"])  return @"iPad Air 3";
    if ([platform isEqualToString:@"iPad11,4"])  return @"iPad Air 3";
    
    // 其他
    if ([platform isEqualToString:@"i386"])   return @"iPhone Simulator";
    if ([platform isEqualToString:@"x86_64"])  return @"iPhone Simulator";
    
    return platform;
}
Copy the code

Complete Device Mode data refer to Wiki: