Big Sur Notifications

Hi everyone - in my app I have put the n(what I think) is the latest macoslib folder.

In “Module1” I have the class named “MyNotificationCenter”.

I have a Method named “NSNotifications”, which contains the following code:

 // ---------------------------------------- DEFINE VARIABLES
    Dim TitleText as string = inTitle
    Dim SubTitleText  as string
    Dim InformativeText  as string = inMSG
    Dim SoundNameText  as string = "Morse"


// ---------------------------------------- DISPLAY NSUserNotification
dim n as New NSUserNotification
if TitleText <> "" then n.Title = TitleText
if SubTitleText <> "" then n.Subtitle = SubTitleText
if InformativeText <> "" then n.InformativeText = InformativeText
if SoundNameText <> "" then n.SoundName = SoundNameText
return n

I also have a Property named “m” (type=MyNotificationCenter)- which as far as I know should all be correct.

In a button’s action event, I have the following code:

// DISPLAY THE USER NOTIFICATION
m = New Module1.MyNotificationCenter
m.DeliverNotification(Module1.NSNotifications("Snippets:","Successfully backed up the database files."))

However - no notification shows up, even though it is enabled in the System Preferences > notifications area.

Im pretty sure this worked in Catalina - can anyone shed some light, or test this?

Thank you all in advance.

Have you tried MBS plugins?

NSUserNotification is quite dead and stopped working some time ago.

Please move to UNNotification, e.g. with UNNotificationMBS class in MBS Xojo Plugins.

… and if you should figure out how to present a notification set to banner in the user’s notification preferences when the apps in foreground, let me know. There is a willPresentNotification event where you can override the type of notification but I have only been successful in making the sound play or show the notification if the style is set to persistent.

Apple deprecated NotificationStyleAlert as a possible reply value so it looks like you cannot override the visibility of a notification for a foreground app anymore in Big sur.

You need to send the correct options to the completion handler of this method:

userNotificationCenter:willPresentNotification:withCompletionHandler:

And while this one is deprecated:

UNNotificationPresentationOptionAlert

It has been replaced with

UNNotificationPresentationOptionBanner

Thanks, Greg! I missed that when I looked at Christian‘s documentation only at that stage.
Sadly, adding 16 does not change anything for me.

Just out of curiosity, what value are you returning? I’d think you’d want both flags at least for now. 16 & 4

I’ll add the missing flag constants for my plugins.

2 Likes

I hate to break it to you, but Apple’s updated HIG now states:

Handle notifications gracefully if your app is in the foreground. Your app’s notifications don’t appear onscreen when your app is in the front, but your app still receives the information. Present it to the user in a way that’s informative but not distracting or invasive. For example, you might display or increment a badge or subtly insert new data into the current view.

Thanks, Greg. Makes one wonder what the Banner flag is good for if it does not change anything, and explains why my best result, not matter what I returned, was to make the notification sound play.

I suspect Banner is for iOS. What I’m really curious about is the List option that currently has no description.