'Code module
#Region Project Attributes
#ApplicationLabel: B4i Example
#Version: 1.0.0
#iPhoneOrientations: Portrait, LandscapeLeft, LandscapeRight
#iPadOrientations: Portrait, LandscapeLeft, LandscapeRight, PortraitUpsideDown
#PlistExtra:<key>NSLocationAlwaysUsageDescription</key><string>Track your location in the background for better ad revenue.</string>
#PlistExtra:<key>NSLocationUsageDescription</key><string>Used to display the current navigation data.</string>
#PlistExtra: <key>UIBackgroundModes</key><array><string>location</string></array>
''#PlistExtra:<key>NSLocationWhenInUseUsageDescription</key><string>Used to display the current navigation data.</string>
''#PlistExtra:<key>NSLocationUsageDescription</key><string>Used to display the current navigation data.</string>
#End Region
Sub Process_Globals
Public App As Application
Public NavControl As NavigationController
Private Page1 As Page
Private locManager As LocationManager
Private lblCount As Label
Private counter As Int = 0
End Sub
Private Sub Application_Start (Nav As NavigationController)
NavControl = Nav
Page1.Initialize("Page1")
Page1.RootPanel.LoadLayout("1")
NavControl.ShowPage(Page1)
locManager.Initialize("locManager")
Dim no As NativeObject = locManager
no = no.GetField("manager")
no.SetField("pausesLocationUpdatesAutomatically", False)
StartBackground(locManager, 0) 'replaces locManager.Start
End Sub
Sub UpdateLabel
lblCount.Text = "Number of updates: " & counter
End Sub
Sub StartBackground(lm As LocationManager, MinimumDistance As Double)
Dim no As NativeObject = lm
no = no.GetField("manager")
If App.OSVersion >= 8 Then
no.RunMethod("requestAlwaysAuthorization", Null)
End If
If App.OSVersion >= 9 Then
no.RunMethod("setAllowsBackgroundLocationUpdates:", Array(True))
End If
no.SetField("distanceFilter", MinimumDistance)
no.RunMethod("startUpdatingLocation", Null)
End Sub
'ActivityType:
'1 - Other
'2 - Automotive Navigation
'3 - Fitness
'4 - Other navigation
Sub AllowPauseLocationAutomatically(lm As LocationManager, ActivityType As Int) 'ignore
Dim no As NativeObject = lm
no = no.GetField("manager")
no.SetField("activityType", ActivityType)
no.SetField("pausesLocationUpdatesAutomatically", True)
End Sub
Sub LocManager_LocationChanged (Location1 As Location)
Log(Location1.Latitude & ", " & Location1.Longitude)
counter = counter + 1
UpdateLabel
End Sub
Sub LocManager_LocationError
Log("error: " & LastException.Message)
End Sub
Private Sub Page1_Resize(Width As Int, Height As Int)
End Sub
Private Sub Application_Background
End Sub