iOS Question UserNotificationCenter Class is this correct

Modern_Digital

Member
Licensed User
Longtime User
Hi,

I modified UserNotificationCenter Class and added a new method, and it works fine :

B4X:
Public Sub CreateNotificationWithContent2(Title As String, Body As String, Identifier As String, Category As String, nDateTimeTick 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 dateComponents As NativeObject
    dateComponents = dateComponents.Initialize("NSDateComponents").RunMethod("new", Null)
    dateComponents.SetField("year", DateTime.GetYear(nDateTimeTick))
    dateComponents.SetField("month", DateTime.GetMonth(nDateTimeTick))
    dateComponents.SetField("day", DateTime.GetDayOfMonth(nDateTimeTick))
    dateComponents.SetField("hour", DateTime.GetHour(nDateTimeTick))
    dateComponents.SetField("minute", DateTime.GetMinute(nDateTimeTick))
    dateComponents.SetField("second", DateTime.GetSecond(nDateTimeTick))
    Dim trigger As NativeObject 
    trigger = trigger.Initialize("UNCalendarNotificationTrigger").RunMethod("triggerWithDateMatchingComponents:repeats:", Array(dateComponents, 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

B4X:
Private Sub UserNotification_Action (Response As Object)
    Dim n As NativeObject = Response
    Dim Identifier As String = n.GetField("notification").GetField("request").GetField("identifier").AsString
    Log("Identifier=" & Identifier)
    Dim ActionIdentifier As String = n.GetField("actionIdentifier").AsString
    Msgbox($"User clicked on : ${ActionIdentifier}"$, "")
End Sub

is what I did right?, I just want to make sure that everything is okay.

Thank you.
 
Top