Click here to Skip to main content
Click here to Skip to main content
Technical Blog

Tagged as

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

, 19 May 2010 CPOL
Rate this:
Please Sign up or sign in to vote.
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 [

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:

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:

    NSString *deviceID = device.uniqueIdentifier;
    

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

    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)

    Share

    About the Author

    MobileAppMastery

    United States United States
    No Biography provided

    Comments and Discussions

     
    -- There are no messages in this forum --
    | Advertise | Privacy | Terms of Use | Mobile
    Web01 | 2.8.150123.1 | Last Updated 19 May 2010
    Article Copyright 2010 by MobileAppMastery
    Everything else Copyright © CodeProject, 1999-2015
    Layout: fixed | fluid