#Region Project Attributes
#ApplicationLabel: Background Fetch
#Version: 1.0.0
#iPhoneOrientations: Portrait, LandscapeLeft, LandscapeRight
#iPadOrientations: Portrait, LandscapeLeft, LandscapeRight, PortraitUpsideDown
#PlistExtra: <key>UIBackgroundModes</key><array><string>fetch</string></array>
#End Region
Sub Process_Globals
Public App As Application
Public NavControl As NavigationController
Private Page1, Page2, Page3, Page4 As Page
Private PVC As PageViewController
Private hd As HUD
Dim notify, CommingFromRequestNotification As Boolean
Dim Selective_Hospitals As List
Public ServerIP As String = "xxxx.com"
End Sub
Private Sub Application_Start (Nav As NavigationController)
Dim rl As ReleaseLogger
rl.Initialize("192.168.1.83", 54323)
#region pvc
Page1.Initialize("Page1")
Page1.RootPanel.LoadLayout("Layout1")
Page2.Initialize("Page2")
Page2.RootPanel.LoadLayout("Layout2")
Page3.Initialize("Page3")
Page3.RootPanel.LoadLayout("Layout3")
Page4.Initialize("Page4")
Page4.RootPanel.LoadLayout("Layout4")
Selective_Hospitals.Initialize
PVC.Initialize("pvc", Array(Page1, Page2, Page3, Page4))
App.KeyController = PVC
#end region
#region ''''''''''''''''notifi
notify = True
App.RegisterUserNotifications(True, True, True) 'request permission for notifications
App.ApplicationIconBadgeNumber = 0
'check whether the app was started from a notification
If App.LaunchOptions.IsInitialized Then
Dim ln As Notification = App.LaunchOptions.Get("UIApplicationLaunchOptionsLocalNotificationKey")
If ln.IsInitialized Then
hd.ToastMessageShow("Application was started from a notification: " & ln.AlertBody, True)
CommingFromRequestNotification=True
End If
End If
Dim no As NativeObject = App
no.RunMethod("setMinimumBackgroundFetchInterval:", Array(0))
Log("set minimum interval")
#end region
End Sub
Sub Application_ReceiveLocalNotification (LN As Notification)
'this event will fire if the scheduled notification happend when the app was running
Log("application received notifivation")
hd.ToastMessageShow("Notification arrived: " & LN.AlertBody, True)
End Sub
Private Sub Application_FetchDownload
'will run every 10 min to detect requests.php , and then jobdone and then notify and then complete
notify=True
' If Notify=True Then
' FetchingDownload
Log("application fetchdownload")
Dim getreq As HttpJob
getreq.Initialize("hostREQ",Me)
getreq.Download("http://" & ServerIP & "csv.php")
' ReadOLDListOfMapsREQ
'' End If
' OLDListOfAllRequests.Initialize
' OLDListPersonsFromService.Initialize
' If File.Exists(File.DirDocuments, "lperson.txt") Then
' Dim raf As RandomAccessFile
' raf.Initialize(File.DirDocuments, "lperson.txt" ,False)
' OLDListPersonsFromService= raf.ReadB4XObject(0) '(raf.CurrentPosition)
' raf.Close
' Dim raf As RandomAccessFile
' raf.Initialize(File.DirDocuments, "lallreq.txt" ,False)
' OLDListOfAllRequests = raf.ReadB4XObject(0) '(raf.CurrentPosition)
' raf.Close
' End If
End Sub
'Private Sub Application_FetchDownload
' Log("FetchDownload")
' Dim ln As Notification
' ln.Initialize(DateTime.Now)
' ln.AlertBody = "fetch download..."
' ln.PlaySound = True
' ln.Register
' Dim getreq As HttpJob
' getreq.Initialize("hostREQ",Me)
' getreq.Download("")
'End Sub
Sub JobDone(Job As HttpJob)
If Job.Success Then
Dim res As String = Job.GetString2("UTF8") 'GetString
Log("Back from Job:" & Job.JobName )
Log("Response from server: " & res)
Select Job.JobName
Case "hostREQ"
Dim ln As Notification
ln.Initialize(DateTime.Now)
ln.AlertBody = res
ln.PlaySound = True
ln.Register
Dim out As OutputStream
out = File.OpenOutput(File.DirTemp,"req.csv",False )
File.Copy2(Job.GetInputStream, out)
out.Close
End Select
End If
Dim No As NativeObject = App
No = No.GetField("delegate")
No.RunMethod("completeFetch:", Array(0))
End Sub