Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

Retrieve the UDID

Fellow developers,

I recently started out with Titanium and loving it so far. It enables me to build things much quicker (seeing how my ObjC skills are pretty much non-existent) but there's one thing I can't seem to figure out: how does one retrieve a device's UDID?

I know that, to be able to use the APNS implementation, one needs the UDID so Titanium must have a way to expose it, but so far, searching the docs has netted me nothing.

Any thoughts?

— asked May 1st 2010 by Kerim Satirli
  • udid
0 Comments

8 Answers

  • Accepted Answer

    After letting this issue rest for a few days and revisiting it, my Google juice returned and I stumbled across this post from February 2010 outlining the correct way to retrieve the UDID:

    Titanium.Platform.id

    I tested it both in the Simulator and on my device and can confirm that it works for me.

    — answered May 5th 2010 by Kerim Satirli
    permalink
    1 Comment
    • Titanium.Platform.id now returns a Titanium-generated UUID that feels like UDID but not the same. You can read about it here.

      — commented March 7th 2013 by Gopi Reddy
  • You get it in iTunes. PLug your device in and then go to the device in iTunes.

    Click on the serial number and it will switch to your UDID. Just hit Command/Ctrl+C and it'll copy to the clipboard.

    — answered May 1st 2010 by Alexander Stone
    permalink
    0 Comments
  • Thanks for the quick attempt at answering. I know how to get my device's UDID from iTunes, but what I want to know is how to expose it programmatically from inside a Titanium based application.

    — answered May 1st 2010 by Kerim Satirli
    permalink
    0 Comments
  • Thanks Aubrey,

    I've seen that code as well but am unable to print the UDID that way (tested in both the Simulator and on an actual device).

    'UDID is: ' + Titanium.Network.remoteDeviceUUID,
    

    simply echos: "UDID is: null".

    Any other thoughts on how to get that kind of information?

    — answered May 2nd 2010 by Kerim Satirli
    permalink
    0 Comments
  • Sorry, this code is for the 1.2 API

    Titanium.Network.registerForPushNotifications({
        types: [
            Titanium.Network.NOTIFICATION_TYPE_BADGE,
            Titanium.Network.NOTIFICATION_TYPE_ALERT,
            Titanium.Network.NOTIFICATION_TYPE_SOUND
        ],
        success:function(e)
        {
            var deviceToken = e.deviceToken;
            label.text = "Device registered. Device token: nn"+deviceToken;
            Ti.API.info("Push notification device token is: "+deviceToken);
            Ti.API.info("Push notification types: "+Titanium.Network.remoteNotificationTypes);
            Ti.API.info("Push notification enabled: "+Titanium.Network.remoteNotificationsEnabled);
        },
        error:function(e)
        {
            label.text = "Error during registration: "+e.error;
        },
        callback:function(e)
        {
            // called when a push notification is received.
            alert("Received a push notificationnnPayload:nn"+JSON.stringify(e.data));
            Titanium.Media.vibrate();
        }
    });    
    
    — answered May 3rd 2010 by Aubrey Cottle
    permalink
    0 Comments
  • Thank you again Aubrey. So am I right to assume that the only way to expose a device's UDID is by signing it up with an APNS?

    It would seem like a very expensive way to get something that is available in ObjC very easily.

    — answered May 3rd 2010 by Kerim Satirli
    permalink
    0 Comments
  • I agree - seems like a lot of code for just the UDID
    (especially if you don't really want/need to use push notifications).

    If you figure this out… please post it here as I need to find a solution to this as well.

    — answered May 4th 2010 by Doug Meade
    permalink
    0 Comments
  • Titanium.Network.registerForPushNotifications({
            types:[
                Titanium.Network.NOTIFICATION_TYPE_BADGE,
                Titanium.Network.NOTIFICATION_TYPE_ALERT,
                Titanium.Network.NOTIFICATION_TYPE_SOUND
            ],
            // this function gives you a device token that must be sent to your server so
            // it can communicate with Apple's Push Service
            success:function(e)
            {
                Titanium.API.info("device token: "+e);
                //NOTE: this value is also available as the property Titanium.Network.remoteDeviceUUID
            },
            // error callback
            error: function(e)
            {
                Titanium.API.info("push notifications disabled: "+e);
            },
    
            // this function is called when you receive a push notification (either while running or at startup)
            // if you received a notification when you weren't running
            callback:function(e)
            {
                var a = Titanium.UI.createAlertDialog();
                a.setMessage("callback: "+Titanium._JSON(e));
                a.show();
            }
    });
    
    — answered May 1st 2010 by Aubrey Cottle
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.