Solution policy for unique UUID of enterprise-level applications after ios5

Source: Internet
Author: User
Tags deprecated

See the apple documentation. From IOS 5.0, The uniqueidentifier attribute in uidevice is no longer valid:

Deprecated on iOS 5.0

Uniqueidentifier

Do not use the uniqueidentifier property. To create a unique identifierspecific to your app, you can call the cfuuidcreate function to create a uuid, and write it to the defaults database using the nsuserdefaults class.

This is a disaster for many applications (especially enterprise applications) associated with device udids. However, in the face of Apple's strong practices, we have no choice. As Apple said, use the cfuidcreate function to replace uniqueidentifier and save it to the program's ults database.

I don't know how many people started to update the old uniqueidentifier code, but I found a 3rd-party open-source Library: UIDevice-with-UniqueIdentifier-for-iOS-5 on GitHub, which solved a lot of trouble for us:

Https://github.com/gekitz/UIDevice-with-UniqueIdentifier-for-iOS-5

It actually includes two category:

Nsstring + md5addition and uidevice + identifieraddition

Copy the four. m Files And. H files to the project and import them directly.

According to the README file, there are two Identifier Types, which are generated by [[uidevice currentdevice] uniquedeviceidentifier] and [[uidevice currentdevice] uniqueglobaldeviceidentifier] respectively.

The former is unique in the same app, and the latter is still unique in different apps.

For the former, it uses the "MAC address + bundleidentifier" scheme to generate the MD5 value as the identifier:

-(Nsstring *) uniquedeviceidentifier {
Nsstring * macaddress = [[uidevice currentdevice] macaddress];
Nsstring * bundleidentifier = [[nsbundle mainbundle] bundleidentifier];
Nsstring * stringtohash = [nsstringstringwithformat: @ "% @", macaddress, bundleidentifier];
Nsstring * uniqueidentifier = [stringtohash stringfrommd5];
Return uniqueidentifier;
}

 

The latter uses the MD5 value generated by the "MAC address" as the identifier (because the MAC address itself is a guid ):

- (NSString *) uniqueGlobalDeviceIdentifier{    NSString *macaddress = [[UIDevice currentDevice] macaddress];    NSString *uniqueIdentifier = [macaddress stringFromMD5];        return uniqueIdentifier;}

 

If you want to maintain compatibility with IOS 4.0, you can write as follows:

// IOS 5.0: uniqueidentifier is deprecated

# If _ iphone_ OS _version_min_required> = _ iphone_5_0

Return [[uidevicecurrentdevice] uniquedeviceidentifier];

# Endif

 

Return [[uidevicecurrentdevice] uniqueidentifier];

Reprinted: http://blog.csdn.net/kmyhy/article/details/7819878

-----------------------------------------------------------------

Udid replacement
Apple began to refuse to use udid in app development. Fortunately, we have a replacement for udid.

1. Replace udid with MAC address

The Open Source Code implemented by George Kitz can claim the unique identifier of the device based on the MAC address of different devices. GitHub download (115 download) is quite simple to use.

2. Create UUID for different users

It is reported that using a MAC address may cause some potential privacy problems. If you do not need a unique identifier of your device, but only need to distinguish different users, you can use cfuidcreate () create your own UUID.

Now, extend the nsstring class:

@ Interface nsstring (UUID)
+ (Nsstring *) UUID;
@ End
 
@ Implementation nsstring (UUID)
+ (Nsstring *) UUID
{
Nsstring * uuidstring = nil;
Cfuuidref UUID = cfuuidcreate (null );
If (UUID ){
Uuidstring = (nsstring *) cfuuidcreatestring (null, UUID );
Cfrelease (UUID );
}
Return [uuidstring autorelease];
}
@ End
Then we create UUID

# Define uuid_user_defaults_key @ "UUID"
 
-(Bool) Application :( uiapplication *) Application didfinishlaunchingwitexceptions :( nsdictionary *) launchoptions
{
Nsuserdefaults * defaults = [nsuserdefaults standarduserdefaults];
If ([defaults objectforkey: uuid_user_defaults_key] = nil ){
[Defaults setobject: [nsstring UUID] forkey: uuid_user_defaults_key];
[Defaults synchronize];
}
 
...
Address: http://oleb.net/blog/2011/09/how-to-replace-the-udid/

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.