iOS Question Unique device ID and name

nwhitfield

Active Member
Licensed User
For the authentication scheme in the API on my site, I need a unique device ID. I can't see an obvious command to get that (and, ideally, the short name, so that on the website we can list devices authorised to access someone's account).

Is this something I need to access via NativeObject for the time being? Or have I missed something (flu, and delays in getting an iOS device, mean I'm a bit behind the curve right now).

Nigel
 

Erel

Administrator
Staff member
Licensed User
There is no simple way to get a unique ID in Android and it is even more complicated in iOS.

You can create a random id and save it in a file.

Or you can use this code to get a unique per vendor id.
B4X:
Sub GetVendorIdentifier As String
   Dim no As NativeObject
   no = no.Initialize("UIDevice").RunMethod("currentDevice", Null)
   Dim id As Object = no.GetField("identifierForVendor").GetField("UUIDString")
   Return id
End Sub
https://developer.apple.com/library...le_ref/occ/instp/UIDevice/identifierForVendor
 
Upvote 0

nwhitfield

Active Member
Licensed User
That's perfect, thanks. As long as it doesn't change, it'll do nicely. And I see that
B4X:
Dim id As Object = no.GetField("name")
will return the device name like "Nigel's iPad" which is all we need to know to allow people to see which devices are linked to their web account
 
Upvote 0

MikeH

Well-Known Member
Licensed User
Upvote 0

Shay

Well-Known Member
Licensed User
I used
GetVendorIdentifier, but yesterday apple push some update and this number changed

so you suggest generate id and save to disk?
do you have any code example ready for this?

Also if user will uninstall and install the app, the file will be deleted, can I save it on "general" place where no matter if my app is been remove, it will stay?
 
Last edited:
Upvote 0

MikeH

Well-Known Member
Licensed User
I`d like to know the best way to do this also.

Creating a unique ID would be quite easy, but where to store it?
 
Upvote 0

Shay

Well-Known Member
Licensed User
and another idea I have, if I am using notification messaging and apple generate ID for me (token)
is this token number can change or I can use this token as my unique ID?
 
Upvote 0

Indy

Active Member
Licensed User
Hi Erel,

I have an app which I built in Android. I now am looking into converting to iOS, so will be downloading B4I trial to see if it's possible. However, one of the checks that I make on this app is to ensure the device being used is authorised to use our corporate remote site. I achieve this by getting the device ID that each device has and passing it to our web service, which performs a lookup. You knidly provide the following code to the Android users which I have been using.:)

B4X:
Dim r As Reflector
   Dim Api As Int
   Api = r.GetStaticField("android.os.Build$VERSION", "SDK_INT")
   If Api < 9 Then
     'Old device
     If File.Exists(File.DirInternal, "__id") Then
       Return File.ReadString(File.DirInternal, "__id")
     Else
       Dim id As Int
       id = Rnd(0x10000000, 0x7FFFFFFF)
       File.WriteString(File.DirInternal, "__id", id)
       Return id
     End If
   Else
     'New device
     Return r.GetStaticField("android.os.Build", "SERIAL")
   End If

Is there no iOS equivilant of the above? If not then I'm stuck for the iOS conversion :(.

Thanks
 
Upvote 0
Top