iOS Question App.GetScheduledNotifications

karyadi

Member
Licensed User
Longtime User
Hi All,

I build apps that can receive local Notifications,
i use this example code
B4X:
'Code module
#Region  Project Attributes
    #ApplicationLabel: B4i Example
    #Version: 1.0.0
    'Orientation possible values: Portrait, LandscapeLeft, LandscapeRight and PortraitUpsideDown
    #iPhoneOrientations: Portrait, LandscapeLeft, LandscapeRight
    #iPadOrientations: Portrait, LandscapeLeft, LandscapeRight, PortraitUpsideDown
#End Region

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)
    NavControl = Nav
    Page1.Initialize("Page1")
    Page1.Title = "Page 1"
    Page1.RootPanel.Color = Colors.White
    Page1.RootPanel.LoadLayout("1")
    NavControl.ShowPage(Page1)
    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)
        End If
    End If
End Sub


Sub btnNotification_Click
    Dim ln As Notification
    ln.Initialize(DateTime.Now + 6 * DateTime.TicksPerSecond) '6 seconds from now
    ln.IconBadgeNumber = 1
    ln.AlertBody = "Moo is hungry"
    ln.PlaySound = True
    ln.Register
    hd.ToastMessageShow("Notification will fire in 6 seconds.", False)
End Sub

Sub Application_ReceiveLocalNotification (LN As Notification)
    'this event will fire if the scheduled notification happend when the app was running
    hd.ToastMessageShow("Notification arrived: " & LN.AlertBody, True)
End Sub
Private Sub Page1_Resize(Width As Int, Height As Int)
 
End Sub

Private Sub Application_Background
 
End Sub


it's working, but how do i schedule it that can trigger notification every 5 minutes? (while apps in background mode, foreground mode)
in this example it's use btnNotification_Click to trigger notification.

please help me with example.
thanks all
 
Last edited:
Top