In my app, I need a notification that is displayed on the lock screen and is not immediately pushed to the notification center. You can do this by declaring a notification as “time critical”. Now I don't know how to integrate the whole thing correctly with Native Object. My following code returns an
Thanks
Object was not initialized (NSObject)
error.UNNotificationInterruptionLevel | Apple Developer Documentation
Constants that indicate the importance and delivery timing of a notification.
developer.apple.com
UNNotificationInterruptionLevel.timeSensitive | Apple Developer Documentation
The system presents the notification immediately, lights up the screen, can play a sound, and breaks through system notification controls.
developer.apple.com
B4X:
Public 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))
Dim n2 As NativeObject
ln.SetField("interruptionLevel", n2.Initialize("UNNotificationInterruptionLevel").RunMethod("UNNotificationInterruptionLevelTimeSensitive", Null)) 'Error - Object was not initialized (NSObject)
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
Thanks