Private Sub Application_RemoteNotification (Message As Map, CompletionHandler As CompletionHandler)
Msgbox("","") 'to know if the sub is fired'
If Home.HomePg.IsInitialized Then
CreateNotificationWithContent(Message.Get("titolo"), Message.Get("corpo"), "identifer 2", "category 1", 3000)
Sleep(0)
Wait For (Home.SincronizzaDBInterno) Complete (Result As Object)
End If
CompletionHandler.Complete
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
#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