Search code examples
androidiphonemobilecordovaudid

Get a unique device id using phonegap


I am developing an application using phonegap for both ios and android. My application is going to have a free trial of 5 items, for every additional item the user will have to pay.

My problem is hat i cant get any unique identifier of the device using my app, so a user can use the 5 free items , then uninstall and reinstall the App and get aditional 5 free items.

I have tried using the device.udid provided by phonegap api , but it changes every time i reinstall it.

Any ideas?


Solution

  • Get the MAC address of the device and do a SHA1 hash on it to obfuscate. There is open source code out there for getting it for Android and iOS devices.

    And this type of solution works regardless of if you continue to use PhoneGap or write native code in the future. Also, Apple has no issues with it as far as the App review process is concerned.

    UPDATE: This WAS the right answer up to and through iOS 6, however for all versions of the iOS SDK GREATER THAN 6, this is NO LONGER POSSIBLE. Any attempt to use the low level calls which formerly worked now ALWAY return a MAC Address of 2. Advertising ID and the AdSupport.framework is the only way to. If you have a jailbroken phone and can get root privileges, it might still work. Not sure.