Sub Process_Globals
Public App As Application
Public NavControl As NavigationController
Private Page1 As Page
End Sub
Private Sub Application_Start (Nav As NavigationController)
NavControl = Nav
Page1.Initialize("Page1")
Page1.Title = "Page 1"
Page1.RootPanel.Color = Colors.White
NavControl.ShowPage(Page1)
App.RegisterUserNotifications(True, True, True)
Dim NotificationCenter As NativeObject
NotificationCenter = NotificationCenter.Initialize("UNUserNotificationCenter").RunMethod("currentNotificationCenter", Null)
NotificationCenter.SetField("delegate", Me)
End Sub
Sub Page1_Click
CreateNotificationWithContent("This is the title", "Body", "identifer 2", "category 1", 1000)
End Sub
Sub CreateNotificationWithContent(Title As String, Body As String, Identifier As String, Category As String, MillisecondsFromNow As Long)
Dim ln As NativeObject
ln = ln.Initialize("UNMutableNotificationContent").RunMethod("new", Null)
ln.SetField("title", Title)
ln.SetField("body", Body)
Dim n As NativeObject
ln.SetField("sound", n.Initialize("UNNotificationSound").RunMethod("defaultSound", Null))
If Category <> "" Then ln.SetField("categoryIdentifier", Category)
Dim trigger As NativeObject
trigger = trigger.Initialize("UNTimeIntervalNotificationTrigger").RunMethod("triggerWithTimeInterval:repeats:", Array(MillisecondsFromNow / 1000, False))
Dim request As NativeObject
request = request.Initialize("UNNotificationRequest").RunMethod("requestWithIdentifier:content:trigger:", _
Array(Identifier, ln, trigger))
Dim NotificationCenter As NativeObject
NotificationCenter = NotificationCenter.Initialize("UNUserNotificationCenter").RunMethod("currentNotificationCenter", Null)
NotificationCenter.RunMethod("addNotificationRequest:", Array(request))
End Sub
Private Sub Page1_Resize(Width As Int, Height As Int)
End Sub
Private Sub Application_Background
End Sub
#AdditionalLib: UserNotifications.framework
#if OBJC
#import <UserNotifications/UserNotifications.h>
@end
@interface b4i_main (notification) <UNUserNotificationCenterDelegate>
@end
@implementation b4i_main (notification)
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
willPresentNotification:(UNNotification *)notification
withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler {
completionHandler(UNNotificationPresentationOptionAlert | UNNotificationPresentationOptionSound );
}
#End If