Get Unique Uuid/udid Scenario

Source: Internet
Author: User

Overview

How do you ensure that the acquired UUID uniquely identifies each device? We know that uuidstring can be obtained through uidevice, but if the app is removed and then reinstalled, it will get a different uuidstring, which is not what we want.

So, is there any way to solve this problem? Here does not say everything before 5.0, only say after 6.0 how to do.

The following is just a snippet of code, not a complete code!

Case

After the iOS6.0 version, Apple provides the following properties in Uidevice:

123 @property(nullable, nonatomic,readonly,strong) nsuuid *identifierforvendor

With this property, you get to the UUID:

1234 / * Return A string description of the UUID, such as "e621e1f8-c36c-495a-93fc-0c247a3e6e5f" * / @property (readonly, copy) nsstring *uuidstring;

Let's do this by running an app first, then printing the uuidstring:

123 b907009b-8c63-4ca8-b3fb-b2724ae96dd5

Then remove the app, reinstall it, and then print it out:

123 b907009b-8c63-4ca8-b3fb-b2724ae96dd5

Why is it the same? Doesn't that mean it's going to change? Yes, because there are other apps on the phone that belong to the same developer as the app. Now, we remove all the apps that are the same developer as it is, then reinstall them and print them as follows:

123 1a73d3a3-3cd6-4655-8566-042fe7c8b2ac

Sure enough, something has changed.

Official documents

Apple's official documents say so:

The value of this property is the same for apps, come from the same vendor running on the same device. A different value is returned for apps on the same device this come from different vendors, and to apps on different Devi Ces regardless of vendor.

The value of this property may be nil if the app was running in the background, before the user have unlocked the device the First time after the device has been restarted. If The value is nil, wait and get the value again later.

The value of the remains the same while the app (or another app from the same vendor) are installed on the IOS de Vice. The value changes when the user deletes any of that vendor's apps from the device and subsequently reinstalls one or more of them. Therefore, if your app stores the value of this property anywhere, you should gracefully handle situations where the ident Ifier changes.

The meaning is probably that:

Run apps from the same developer on the same device, and get the same value for the Uuidstring property. When you run apps from different developers on the same device, the uuidstring you get is different. On different devices, whether or not they belong to the same developer, the uuidstring will be different.

When the device restarts, the uuidstring may be nil if the user does not unlock the device for the first time while the app is running in the background. If the value is nil, wait and fetch again later.

When apps or apps from the same developer are installed on the same device, the uuidstring will be consistent (such as the small example above, the print is consistent). When the user removes the app from all the same developers on the device, reinstalling one of the apps will change the uuidstring. So, regardless of where the App Store stores the UUID, you should handle this change manually.

So how do we solve this change?

Solution Solutions

The solution is to have the generated uuidstring stored in keychain, using the same access group, the same identifier. Each time the UUID is obtained, it is obtained from keychain, and if it is empty, the uuidstring is obtained by Uidevice and stored to keychaing, the code version is as follows:

12345678910111213 + (nsstring *)UUID {     keychainitemwrapper *wrapper = [[KeychainItemWrapper< Span class= "crayon-h" > alloc] Initwithidentifier:@ "dujianchaoappid" Accessgroup:@ "Com.dujianchao.test.group" ] nsstring *uuid = [wrapper Objectforkey:(__bridge ID )Ksecvaluedata];         if (uuid. Length == 0 {       UUID Span class= "Crayon-o" >= [[ [uidevice Currentdevice] Identifierforvendor]< Span class= "CRAYON-E" > Uuidstring]; [wrapper setobject: UUID forkey:(__bridge ID)ksecvaluedata] ;    }   return UUID; }

Please modify it yourself ~

Get Unique Uuid/udid Scenario

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.