#Region Project Attributes
#ApplicationLabel: B4i Network Monitor
#Version: 1.0.0
#iOSKeychainAccessGroups:
#End Region
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
Sub Process_Globals
Private monitor As NativeObject
End Sub
Sub Application_Start (Nav As NavigationController)
NavControl = Nav
Page1.Initialize("Page1")
Page1.Title = "Network Monitor"
Page1.RootPanel.LoadLayout("MainLayout")
NavControl.ShowPage(Page1)
monitor = CreateNWPathMonitor
StartMonitoring
End Sub
Private Sub CreateNWPathMonitor As NativeObject
Dim no As NativeObject
no = no.Initialize("NWPathMonitor").RunMethod("new", Null)
Return no
End Sub
Private Sub StartMonitoring
monitor.RunMethod("setPathUpdateHandler:", Array(CreateWrapper("pathUpdateHandler:")))
monitor.RunMethod("startWithQueue:", Array(CreateWrapper("globalQueue")))
End Sub
Private Sub pathUpdateHandler(path As NativeObject)
Dim status As Int = path.GetField("status").AsNumber
If status <> 1 Then ' NWPathStatusSatisfied == 1
Log("Not connected")
Else
Dim usesCellular As Boolean = path.RunMethod("usesInterfaceType:", Array(4)).AsBoolean ' NWInterfaceTypeCellular == 4
Dim usesWiFi As Boolean = path.RunMethod("usesInterfaceType:", Array(1)).AsBoolean ' NWInterfaceTypeWiFi == 1
Dim usesEthernet As Boolean = path.RunMethod("usesInterfaceType:", Array(2)).AsBoolean ' NWInterfaceTypeWiredEthernet == 2
If usesCellular Then
Log("Cellular connection")
ElseIf usesWiFi Then
Log("Wi-Fi connection")
ElseIf usesEthernet Then
Log("Ethernet connection")
End If
End If
End Sub
Private Sub CreateWrapper(MethodName As String) As NativeObject
Dim no As NativeObject
no.Initialize("B4I" & MethodName)
Return no
End Sub
Private Sub globalQueue As NativeObject
Return NativeObject.Initialize("dispatch_get_global_queue", Array(4, 0)) ' QOS_CLASS_BACKGROUND == 4
End Sub