iOS Code Snippet Getting Device Properties

This has been sources from questions asked, just consolidated it here...

B4X:
Sub GetDeviceSystemName As String
    ' get the system name of the device
    Dim device As NativeObject
    device = device.Initialize("UIDevice").RunMethod("currentDevice", Null)
    Dim name As Object = device.GetField("systemName").AsString
    Return name
End Sub

Sub GetDeviceModel As String
    ' get the device model
    Dim device As NativeObject
    device = device.Initialize("UIDevice").RunMethod("currentDevice", Null)
    Dim name As Object = device.GetField("model").AsString
    Return name
End Sub

Sub GetDeviceName As String
    ' get the device name
    Dim device As NativeObject
    device = device.Initialize("UIDevice").RunMethod("currentDevice", Null)
    Dim name As Object = device.GetField("name").AsString
    Return name
End Sub

Sub GetIMEI As String
    ' get device unique identifier
    Dim device As NativeObject
    device = device.Initialize("UIDevice").RunMethod("currentDevice", Null)
    Dim name As String = device.GetField("identifierForVendor").AsString 
    Return name
End Sub

Sub GetPackageName As String
   ' get your app package name
   Dim no As NativeObject
   no = no.Initialize("NSBundle").RunMethod("mainBundle", Null)
   Dim name As Object = no.RunMethod("objectForInfoDictionaryKey:", Array("CFBundleIdentifier"))
   Return name
End Sub

Sub GetAppName As String
    ' get app name
   Dim no As NativeObject
   no = no.Initialize("NSBundle").RunMethod("mainBundle", Null)
   Dim name As Object = no.RunMethod("objectForInfoDictionaryKey:", Array("CFBundleDisplayName"))
   Return name
End Sub

Sub GetVersion As String
   Dim no As NativeObject
   no = no.Initialize("NSBundle").RunMethod("mainBundle", Null)
   Dim name As Object = no.RunMethod("objectForInfoDictionaryKey:", Array("CFBundleShortVersionString"))
   Return name
End Sub
 

Yvon Steinthal

Active Member
Licensed User
Hello, quick question!
Can i stock these info in a DB? I mean is it allowed by Apple?
Im guessing so if they allow access...
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…