Click here to Skip to main content
15,893,668 members
Articles / Programming Languages / C++

How to Uniquely Identify Your User’s iPhone, iPad or iPod with UIDevice

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
19 May 2010CPOL2 min read 12.5K   4  
How to uniquely identify your user's iPhone, iPad or iPod with UIDevice

Post image for How To Uniquely Identify Your User’s iPhone, iPad or iPod With UIDevice

Have you ever wanted a way to uniquely identify your user’s device? This is something that comes in handy when you are trying to implement a data syncing scheme or if you want to provide unique web based content to your user. If this sounds like something you want to do, read on to find out how.

Get A Reference to the Current Device

UIDevice is a class that stores information about the physical device that is running your app. You use UIDevice to get important information by using the currentDevice function. This is return a UIDevice object filled with information about the device that is running. Here is how to get this reference:

C++
UIDevice *device = [UIDevice currentDevice];

Here is What UIDevice Will Tell You

UIDevice objects will store more information that a simple unique identifier. You may use this object to get all kinds of information that will come in handy in this world of multiple devices. Here is what you get:

  • name – what the user named the device
  • model – iPhone, iPod or iPad
  • systemName – pretty much “iPhone OS”
  • systemVersion – tells you what iPhone OS version the system is running
  • orientation – what direction the device is currently facing
  • uniqueIdentifier – a string unique to each device based on information from the hardware itself

uniqueIdentifier Can Be Pretty Useful

You retrieve all of this information in the same way by accessing the UIDevice object properties. Here is how to get the unique identifier from the device object we referenced above:

C++
NSString *deviceID = device.uniqueIdentifier;

And of course, you may use this string in the normal ways:

C++
NSLog(@"%@", deviceID);

You will get something that looks a bit like this:

XXX70A50-ER31-X3X3-BDB2-3ED40EKIUN4D

Why Do It?

Of course, the why is up to you. Something that I have thought about is the situation where I want to be able to store user’s data for syncing purposes. You may also want to have your users share data or content with other apps, websites and so on. A simple way to start implementing this functionality could be to use this string to create a folder (or database primary key) to store your user’s data. Of course, you will need to do a bit more work on top of this as well.

What do you think – useful trick?

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
-- There are no messages in this forum --