UserNotificationCenter class
A class that creates local notifications based on the newer iOS 10+ API. The notifications are configured to show even when the app is in the foreground. You can also add actions to the notifications: See the attached example
I would like to display a notification without the popup appearing (without an alert). According to Apple's documentation, I can do this with the “UNNotificationPresentationOptionNone” option. How can I use this with the UserNotificationCenter class?
From the UserNotificationCenter class:
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))
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
#if OBJC
#import <UserNotifications/UserNotifications.h>
@end
@interface b4i_usernotificationcenter (notification) <UNUserNotificationCenterDelegate>
@end
@implementation b4i_usernotificationcenter (notification)
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
willPresentNotification:(UNNotification *)notification
withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler {
completionHandler(UNNotificationPresentationOptionAlert | UNNotificationPresentationOptionSound );
}
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
didReceiveNotificationResponse:(UNNotificationResponse *)response
withCompletionHandler:(void (^)(void))completionHandler {
B4I* bi = [b4i_main new].bi;
[bi raiseEvent:nil event:@"usernotification_action:" params:@[response]];
completionHandler();
}
#End If
Thanks