iOS Question Device ID always different in iTunes released App

semar

Active Member
Licensed User
Longtime User
All,
I have this function to retrieve an unique device ID:
B4X:
Sub GetDeviceId As String
    
   Dim no As NativeObject
   no = no.Initialize("UIDevice").RunMethod("currentDevice", Null)
   Dim id As Object = no.GetField("identifierForVendor").GetField("UUIDString")
   MyDeviceID = id
   Return id

End Sub
By debugging it works. It works also flawlessy when I deploy the App on the iPhone, the device ID is always the same and is unique even when I delete the App from the iPhone and then re-install it from within B4I.

So far, so good. In this way I've build a score table in the cloud, using that ID as unique identifier of an user. I though, this ID remains unique and so a returned user, which re-install the app, will be again recognized using that ID.

With my big surprise, after I uploaded the (same) App to iTunes, the ID I get each time I re-install the app an run it, is always different ! You may imagine the side effect: the score table is completely screwed up, since it is based on the uniqueness of the DeviceID.

Am I missing something obvious here ? Why the same function returns always - as expected - the same ID at each reinstall when I deploy it directly on the iPhone, but when I dowload the (same) App from iTunes I get different IDs each time I re-install it ?

To summarize:
Development scenario
- I deploy from within B4I the app on the device
- run the App, get a device ID
- uninstall the app
- reinstall the app
- run the App, get the same device ID - as expected

iTunes scenario:
- I download the App from iTunes and install it on the device
- run the App, get a device ID
- I uninstall the App from the device
- I download agein the App from iTunes and install it on the device
- run the App, get a different device ID

Any help would greatly appreciated.

Sergio
 

semar

Active Member
Licensed User
Longtime User
Thank Erel.

The identifierForVendor is reset whenever the last vendor app is uninstalled.
---> Does that mean, that I can't rely on it ? Does it change every time the App is re-installed ?

You can use keychain instead to store a random id.

---> How can I use keychan ? Is there an example ready to use ?

Alternatively I could use the name of the device and the model. In this way I could have, for example:
John-iPhone
John-iPad

But a relyable unique device ID would be great
 
Upvote 0
Top