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).
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
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?
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?
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 .