'Code module
#Region Project Attributes
#ApplicationLabel: B4i Background
#Version: 1.0.0
'Orientation possible values: Portrait, LandscapeLeft, LandscapeRight and PortraitUpsideDown
#iPhoneOrientations: Portrait, LandscapeLeft, LandscapeRight
#iPadOrientations: Portrait, LandscapeLeft, LandscapeRight, PortraitUpsideDown
#Target: iPhone, iPad
#ATSEnabled: True
#MinVersion: 7
#End Region
'Link --> https://www.b4x.com/android/forum/threads/background-fetch-downloads.56022/#content
'Per Sviluppo non distribuzione
#CertificateFile: ios_development.cer
#ProvisionFile: Ultimo.mobileprovision
#PlistExtra: <key>UIBackgroundModes</key><array><string>fetch</string></array>
Sub Process_Globals
'These global variables will be declared once when the application starts.
'Public variables can be accessed from all modules.
Public App As Application
Public NavControl As NavigationController
Private Page1 As Page
Private hd As HUD
End Sub
Private Sub Application_Start (Nav As NavigationController)
'SetDebugAutoFlushLogs(True) 'Uncomment if program crashes before all logs are printed.
NavControl = Nav
Page1.Initialize("Page1")
Page1.Title = "Page 1"
Page1.RootPanel.Color = Colors.White
NavControl.ShowPage(Page1)
'For Notification
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)
Log("Application was started from a notification")
End If
End If
Dim no As NativeObject = App
no.RunMethod("setMinimumBackgroundFetchInterval:", Array(0)) '0 = minimum interval
End Sub
Private Sub Application_FetchDownload
Log("FetchDownload")
Dim ln As Notification
ln.Initialize(DateTime.Now)
ln.IconBadgeNumber = 1
ln.AlertBody = "Fetch download..."
ln.PlaySound = True
ln.Register
Dim no As NativeObject = App
no = no.GetField("delegate")
no.RunMethod("completeFetch:", Array(0))
End Sub
Private Sub Page1_Resize(Width As Int, Height As Int)
End Sub
Private Sub Application_Background
Log("sono in background")
End Sub
Private Sub Application_Foreground
App.ApplicationIconBadgeNumber=0
End Sub
Sub Application_ReceiveLocalNotification (ln As Notification)
'this event will fire if the scheduled notification happend when the app was running
hd.ToastMessageShow("NA: " & ln.AlertBody, True)
End Sub