How IOS gets unique identifiers for devices

Source: Internet
Author: User

In development, applications need to record device markings, even if the app is uninstalled and then re-identified, in this way, write an implementation-read the device's UUID (universally Unique Identifier) and record through keychain.

The first way to get device unique identifiers in iOS has always changed with the version update. After IOS 2.0, Uidevice provides a method for acquiring a unique identifier for a device uniqueidentifier, which allows us to obtain the serial number of the device, which is the only identifier that can be confirmed so far. Not for the time being, because the unique identifier corresponds to the phone one by one, Apple thought it might reveal the user's privacy, so the method was discarded after iOS 5.0, and the iOS 6.0 system added two new interfaces for replacing the uniqueidentifier. These are: Identifierforvendor,advertisingidentifier, but these two interfaces will change the value when the app is reinstalled, not the unique identifier, so the developer instead uses the WiFi MAC address instead; IOS 7 Apple also blocked the MAC address, so the developers change their mind again use Keychain to save the Udid, so that even if the app is deleted and then loaded back, you can read back from the keychain.

First save the device's UUID, you can use the class method + (ID) UUID is a class method, call the method can obtain a UUID. A UUID string can be obtained by using the following code:

NSString *uuid = [[Nsuuid uuid] uuidstring]


You can also save the new Vindor identifier (Idfv-identifierforvendor) in iOS 6, which is added to the existing Uidevice class for this IDFV. As with Advertisingidentifier, this method returns a Nsuuid object.

NSString *IDFV = [[[Uidevice Currentdevice] Identifierforvendor] uuidstring];


If the user unloads all the programs for the same vendor, and then reinstall the same vendor-provided program, Identifierforvendor is reset, so keychain is used to save it.

KeyChain (keychain) is often used by Apple devices, usually to debug, you have to install certificates and the like, these certificates are stored in the KeyChain, as well as our usual browsing page records of the account password is also recorded in the KeyChain. Keychain in iOS is simpler than OS X, and the whole system has only one keychain, and each program can record data in keychain, and can only read the data recorded in keychain by its own program. The Security.framework framework in iOS provides four main ways to manipulate keychain:

    • Secitemcopymatching (cfdictionaryref query, Cftyperef *result);//Queries Osstatus
    • Secitemadd (cfdictionaryref attributes, Cftyperef *result); Add Osstatus
    • Secitemupdate (cfdictionaryref query, Cfdictionaryref attributestoupdate);//keychain in Update Itemosstatus
    • Secitemdelete (cfdictionaryref query)//delete Itemosstatus in keychain

These four method parameters are more complex, once the error will cause the operation keychain failure, the document described in more detail, you can check the official documents.

/**

* AUTHOR:JN

* Github:https://github.com/jnkindle

* Cnblogs:http://www.cnblogs.com/jnkindle

* qq:1294405741

*/

How IOS gets unique identifiers for devices

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.