iOS Question GUID

daxydoggie

Member
Licensed User
Longtime User
What is the B4i equivalent of the following code to generate a GUID?

Sub GetGUID() As String
Dim r As Reflector
r.Target = r.RunStaticMethod("java.util.UUID", "randomUUID", Null, Null)
Return r.RunMethod("toString")
End Sub
 

imbault

Well-Known Member
Licensed User
Longtime User
Do you mean, you need a unique iOS device ID?

If your answer = yes Then
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
Else If you need a random ID = yes Then
B4X:
Sub RandomUUID As String
   Dim no As NativeObject
   Return no.Initialize("NSUUID").RunMethod("UUID", Null).RunMethod("UUIDString", Null).AsString
End Sub
End If
 
Upvote 0

daxydoggie

Member
Licensed User
Longtime User
Do you mean, you need a unique iOS device ID?

If your answer = yes Then
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
Else If you need a random ID = yes Then
B4X:
Sub RandomUUID As String
   Dim no As NativeObject
   Return no.Initialize("NSUUID").RunMethod("UUID", Null).RunMethod("UUIDString", Null).AsString
End Sub
End If

ThankYou.
 
Upvote 0
Top