UDID and UUID in IOS development

Today, I suddenly want to talk to you about UDID and UUID. Although we usually ignore these two things, it is often difficult to distinguish them. Let’s talk about it today.
【 UDID 】
UDID’s full name is Unique Device Identifier: Device Unique Identifier. As you can see from the name, UDID is device specific and device specific, kind of like a MAC address. In my last blog, iOS App Release Process Details, I mentioned real machine debugging and the need to add UDID to the Provisoning Profile authorization file, which is to add a unique device identifier to identify a device.
UDID is a 40-bit hexadecimal sequence, and we can use iTunes and Xcode to get this value.
(1) iTunes acquisition of UDID:
Connect our phones to our computers and turn on iTunes.
.
By default, this location shows the serial number. Just click the location of the serial number to switch to UDID.

(2) Xcode gets UDID:
Connect your phone to your computer, open Xcode, and select Window–> Devices, all the Devices you are currently connected to are displayed, among which the Identifier displayed is the UDID of the device:
.

But what if we want to use UDID in our code?Unfortunately, since iOS5, apple has banned accessing UDID through code. Previously, you could drive past a device using the method [[UIDevice cuurrent] uniqueIdenfier], which is now impossible. As to why access to UDID is prohibited, I will mention below. In the current SDK, Apple provides a parameter identifierForVendor that replaces the original UDID function. The code is as follows:

NSUUID *uuid = [UIDevice currentDevice].identifierForVendor;
NSLog(@"uuid 1 = %@",uuid.UUIDString);

The string UUIDString that you print out here is not a real UDID, but rather a substitute that looks a little bit like it. As I mentioned above, UDID is only related to iOS devices, while the identifierForVendor is an application related to both the device and the device. An application A is installed on the device to generate an identifierForVendor (for example: 1234). An application installed on li Si’s device will generate another identifierForVendor (e.g. 5678). The B application was installed on zhang SAN’s device, and a new identifierForVendor (e.g. 9999) was installed on Li Si’s device. The B application was also installed on Li Si’s device. However, no matter how many times an application A is installed or uninstalled, the resulting identifier is 1234. So, we know that the identifierForVendor is an identifier generated by an application plus A device binding, equivalent to: Z(identifierForVendor) = X(an application) + Y(A device). Of course, the difference from a real UDID is obvious: App developers have no way to distinguish between a particular device, but can only identify an application on a particular device.

【 UUID 】
Universally Unique Identifier is a Universally Unique Identifier. Is a 32-bit hexadecimal sequence, connected by little horizontal lines: 8-4-4-12. UUID is unique in a given space and time. For example, in the current second, the uUids generated all over the world are different; Of course, the UUID generated by the same device is also different. In an earlier blog post, iOS Project Dev Practice: Getting current UUids, I used what now seems like a silly way to get current UUids. As some readers have reflected, the easiest way to get uUids is as follows:

    for (int i = 0; i < 10; i++)
    {
        NSString *uuid = [NSUUID UUID].UUIDString;
        NSLog(@"uuid 2 = %@",uuid);
    }

By running the program, it can be found that the value printed is different each time after 10 cycles, but no matter how many cycles there are, the value will never be the same. So in a way, the UUID doesn’t have anything to do with your device.

Apple has long said that if third-party app developers continue to share or use UDID on the iPhone, Mac or AppleWatch, their apps will be banned from the shelves. Why would Apple ban it from apps?That’s because of privacy issues. For example, I have developed 5 apps, and many users have downloaded these 5 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 the privacy nature of UDID itself, it was previously used for third-party statistics and other purposes. Now, of course, there are people who use MAC addresses to identify devices, because the MAC address uniquely identifies a device and doesn’t change, and I don’t know how Apple will do that in the future. Here’s Apple’s statement on disabling UDID:
.

Read More: