0

I want to find out the list of mobile devices which are all click my ad. Based on the details I want to re-target them

So I need to capture their identifier(UDID in ios and Android id in android phone) in order to identify them.

Can anyone suggest me good method or prefer any better way to achieve the above.

Inaccessible
  • 1,560
  • 3
  • 18
  • 42
  • You can use either `[[[UIDevice currentDevice] identifierForVendor]UUIDString];` or [OpenUDID](https://github.com/ylechelle/OpenUDID) for `iOS` – Ankur Arya Nov 05 '13 at 09:29
  • @Ankur It's time to stop using OpenUDID -> http://blog.appsfire.com/udid-is-dead-openudid-is-deprecated-long-live-advertisingidentifier/ – borrrden Nov 05 '13 at 09:33
  • Guys thanks for all your comments. I don't have knowledge in android or IOS native program languages. Is there any other api or github projects to find UDID or Android id which should work in both IOS and Android? – Inaccessible Nov 05 '13 at 09:37
  • @borrrden: haven't used `OpenUDID` for quite some time, thanks for the info. – Ankur Arya Nov 05 '13 at 09:39
  • No, why should there be a library that works on both? The iOS version is just the one line that Ankur said. You can't get "UDID" on iOS anymore for privacy reasons. – borrrden Nov 05 '13 at 09:46
  • You can see: http://stackoverflow.com/questions/3226135/android-udid-like-iphone/10085392#10085392 – Hoàng Toản Nov 05 '13 at 09:56

2 Answers2

0

For Android, you should check this thread :

Will TelephonyManger.getDeviceId() return device id for Tablets like Galaxy Tab...?

Jorgesys' answer seems clean.

Community
  • 1
  • 1
Antoine
  • 1,068
  • 10
  • 17
  • Thanks Antoine. I will try this. Do u have any idea for IOS? – Inaccessible Nov 05 '13 at 09:42
  • Sorry, I don't work on iOS. I know there has been some discussion about UDID replacement since Apple banned the actual UDID use in apps. For instance : http://stackoverflow.com/questions/15939819/udid-replacement. I don't know which solution is the best though. – Antoine Nov 29 '13 at 08:59
0

ANDROID: I am using this and seems to be working fine.

public static String getDeviceAndroidID(Context context)
{
    String android_id = Secure.getString(context.getContentResolver(), Secure.ANDROID_ID);
    if(android_id != null)
        return android_id;
    else
        return "";
}

iOS: For iOS version less than 7 I am using MAC address of the device. From iOS version 7 apple is providing a unique ID for this purpose.

(NSString *)getMacAddress
{
if(SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0"))
{
    NSString *strUID = nil;
    if(strUID == nil) strUID = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
    return strUID;
}


int                 mgmtInfoBase[6];
char                *msgBuffer = NULL;
size_t              length;
unsigned char       macAddress[6];
struct if_msghdr    *interfaceMsgStruct;
struct sockaddr_dl  *socketStruct;
NSString            *errorFlag = nil;


// Setup the management Information Base (mib)
mgmtInfoBase[0] = CTL_NET;        // Request network subsystem
mgmtInfoBase[1] = AF_ROUTE;       // Routing table info
mgmtInfoBase[2] = 0;
mgmtInfoBase[3] = AF_LINK;        // Request link layer information
mgmtInfoBase[4] = NET_RT_IFLIST;  // Request all configured interfaces


// With all configured interfaces requested, get handle index
if ((mgmtInfoBase[5] = if_nametoindex("en0")) == 0)
    errorFlag = @"if_nametoindex failure";
else
{
    // Get the size of the data available (store in len)
    if (sysctl(mgmtInfoBase, 6, NULL, &length, NULL, 0) < 0)
        errorFlag = @"sysctl mgmtInfoBase failure";
    else
    {
        // Alloc memory based on above call
        if ((msgBuffer = malloc(length)) == NULL)
            errorFlag = @"buffer allocation failure";
        else
        {
            // Get system information, store in buffer
            if (sysctl(mgmtInfoBase, 6, msgBuffer, &length, NULL, 0) < 0)
                errorFlag = @"sysctl msgBuffer failure";
        }
    }
}
// Befor going any further...
if (errorFlag != nil)
{
    free(msgBuffer);
    if(ENABLE_LOG) DLog(@"Error: %@", errorFlag);
    return errorFlag;
}
// Map msgbuffer to interface message structure
interfaceMsgStruct = (struct if_msghdr *) msgBuffer;
// Map to link-level socket structure
socketStruct = (struct sockaddr_dl *) (interfaceMsgStruct + 1);
// Copy link layer address data in socket structure to an array
memcpy(&macAddress, socketStruct->sdl_data + socketStruct->sdl_nlen, 6);
// Read from char array into a string object, into traditional Mac address format
NSString *macAddressString = [NSString stringWithFormat:@"%02X:%02X:%02X:%02X:%02X:%02X",
                              macAddress[0], macAddress[1], macAddress[2],
                              macAddress[3], macAddress[4], macAddress[5]];
//if(ENABLE_LOG) DLog(@"Mac Address: %@", macAddressString);  
// Release the buffer memory
free(msgBuffer);
return macAddressString;
}
Rohit5k2
  • 17,948
  • 8
  • 45
  • 57
  • Thanks I need a solution for both IOS and android phone.I just need to find or calculate a unique identifier(static in all cases)for both phones. – Inaccessible Nov 05 '13 at 09:40
  • I have added the code for iOS too, try that and let me know if that is working for you! :) – Rohit5k2 Nov 05 '13 at 09:54