iOS Question GUID

Similar threads

B4A Code Snippet [B4X] GUID
B4J Question [B4X] How to get a GUIDType Simple Type / GUID
B4A Code Snippet [B4X] UUID version 4 Generator
B4i Tutorial iBeacons
B4i Tutorial BLE Chat - Connecting Android and iOS

daxydoggie

Member
Licensed 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
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
 

daxydoggie

Member
Licensed 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.
 
Top