7

I need to get the UDID of my iPhone to use in my iOS app.

Some info about my app:

  • My app is not for the public and will never make it to the store, so I can use any 3rd party libraries. It will only be used by some employees at work.

  • My device will always be plugged into a Mac, while my app is running.

The way I see it, there are only 2 ways this can be accomplished.

  1. Use a third party library to get the UDID inside of my iOS app.
  2. Since the iPhone will always be plugged into a Mac while my app is running, how about getting the UDID via the Mac and transferring it in some way to my app in the iPhone.

Any ideas would be appreciated. Thanks.

Edit: Question is, do you know any 3rd party libraries or a better way to get my app to automatically get the iPhone's UDID while running?

Edit 2: I know this can be done using only my phone because of this web app: http://get.udid.io/

How does this work?

donga
  • 135
  • 1
  • 12
  • ...and your question is... is...? – holex Mar 25 '15 at 08:39
  • @holex question is, do you know any 3rd party libraries that can do this? Everything I tried off Github has failed me so far. – donga Mar 25 '15 at 08:55
  • What does this have to do with `osx`? – Popeye Mar 25 '15 at 09:00
  • @Popeye I was hoping there would be a way via some terminal command to send some data to a connected iPhone? The main reason I'm so desperately in need to getting the UDID is because osx instruments can only identify devices via the devices UDID. Is there a workaround for this? – donga Mar 25 '15 at 09:05
  • Is it possible to get this with private API? If so, which one? I would also be interested in this. – Legoless Mar 25 '15 at 09:14

6 Answers6

2

If you're trying to read the UDID to automate something on the Mac, then you can use something like system_profiler SPUSBDataType to get the UDID, for my phone the entry:

          Product ID: 0x12a8
          Vendor ID: 0x05ac  (Apple Inc.)
          Version: 7.01
          Serial Number: 7bed*********************************33
          Speed: Up to 480 Mb/sec
          Manufacturer: Apple Inc.
          Location ID: 0x1d110000 / 6
          Current Available (mA): 500
          Current Required (mA): 500
          Extra Operating Current (mA): 1600

The line Serial Number is the UDID (I've starred it out as I'm stupidly paranoid).

Note, that without the UDID you could never have got the app onto the phone in the first place.

You could run a small daemon process on the mac, reading this information and creating a bonjour service that provides the information to requestors - it's a SMOP.

Anya Shenanigans
  • 91,618
  • 3
  • 107
  • 122
  • Thanks, this is what I was thinking of actually. My situation gets a little more complicated: what if there is more than 1 device connected? 2 iPhones for example? How can I differentiate which iPhone the app is running on? – donga Mar 25 '15 at 09:50
  • That's a bit more awkward, but if you know about using http://get.udid.io/, then you can [set up your own server](http://stackoverflow.com/questions/19032162/is-there-a-way-since-ios-7s-release-to-get-the-udid-without-using-itunes-on-a), and once you have your own server, you should be able to return this UDID to the phone if it requests it (I've not tested accomplishing this). – Anya Shenanigans Mar 25 '15 at 14:29
2

It's very simple. Go to Xcode Window and select Devices or you can find it in Organizer. enter image description here

http://www.raywenderlich.com/2915/ios-code-signing-under-the-hood/organizerudid

swathy krishnan
  • 916
  • 9
  • 22
1

From a quick look online, it looks like you can use a private framework called libMobileGestalt.dylib.

After linking the library and importing the header, you should be able to do something like this (reference):

CFStringRef value = MGCopyAnswer(kMGUniqueDeviceID);
NSLog(@"Value: %@", value);
CFRelease(value);

On my Mac, I can find that particular dylib here:

/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/lib/libMobileGestalt.dylib
Sandy Chapman
  • 11,133
  • 3
  • 58
  • 67
  • libMobileGestalt MobileGestalt.c:534: no access to UniqueDeviceID (see ) – Anya Shenanigans Mar 25 '15 at 14:07
  • @Petesh, you also need to grant your app an entitlement to successfully use this. See [this answer for that](http://stackoverflow.com/a/27686125/119114). – Nate Mar 15 '17 at 06:40
0

Use this code in ios 9

NSUUID *tempUUID = [[UIDevice currentDevice] identifierForVendor];
NSString *stringForUDID =  [tempUUID UUIDString];
NSCharacterSet *notAllowedChars = [[NSCharacterSet characterSetWithCharactersInString:@"1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"] invertedSet];
NSString *resultString = [[stringForUDID componentsSeparatedByCharactersInSet:notAllowedChars] componentsJoinedByString:@""];
NSLog(@"Final string %@", resultString);
Maninderjit Singh
  • 1,419
  • 1
  • 13
  • 23
0

Here is the github project which seems correct for your requirement

Here is the code that works

#import <Foundation/Foundation.h>
#import <CoreFoundation/CoreFoundation.h>
#import <liblockdown.h>
#include <stdio.h>

...
    LockdownConnectionRef connection = lockdown_connect();

    CFStringRef udid = (CFStringRef)lockdown_copy_value(connection, NULL, kLockdownUniqueDeviceIDKey);
    CFShow(udid);

    lockdown_disconnect(connection);
Jagat Dave
  • 1,643
  • 3
  • 23
  • 30
Mihir Mehta
  • 13,743
  • 3
  • 64
  • 88
-2

Use this: [[[UIDevice currentDevice] identifierForVendor] UUIDString];

Akshay Bhalotia
  • 799
  • 4
  • 11
  • 9
    UUID != UDID. Not the same thing. – gnasher729 Mar 25 '15 at 08:47
  • 1
    UUID will not stay the same after a reinstallation. I specifically want the UDID because later on, I want my web service to be able to identify the device via UDID. – donga Mar 25 '15 at 08:52