Best or expected behaviour for a notification when app is in front

I was testing apps known to give notifications such as Transmit, not my own. I was checking behavior, so I was trying to avoid my own code (that and only ExeWrapper gives notifications).

All of my notifications are somehow muffled, but I’m really not upset about that. I can’t find an obvious setting for Notification Center regarding this behavior so I can’t change it to test. Quite pleased with how it currently behaves, so I’m not trying to poke the bear :sweat_smile:

1 Like

IMHO, Xojo just needs to port the one we did for iOS. It should be “relatively easy” and it would be nice to have a cross-platform api.

3 Likes

Unlike NSNotification, UNNotification does indeed require that the app be signed. So I also have my AppWrapper build script set to run in the debugger.

On my projects that support pre-Mojave, I check the system to decide which to use.

2 Likes

Transmit shows its transfer completed notification even when it’s frontmost.

2 Likes

Using UNNotificationRequestMBS is as simple as the old notification type. But the app also need to be in the background.

Screenshot 2023-04-15 at 05.32.41

1 Like

@Beatrix_Willius
Not true, see my posts above. I’m using UNUserNotificationCenterMBS and notifications I send with UNUserNotificationCenterMBS are received when my app is in front. I just tried it, running in the debugger (and signed), and it worked.

Ventura 13.1.1, Xojo 2023r1.1, MBS 23.2pr1

Since we’re all using MBS, maybe @Christian_Schmitz has some insight into why it’s working for some and not others.

Well, there is a willPresentNotification event in UNUserNotificationCenterMBS class, so you can decide whether the notification shows while your app is running.

4 Likes

Here’s how I solved the notification issue in a desktop app:
I don’t like to show message boxes if not necessary as they interrupt the workflow – user has to click “ok” each time.
I installed a notification DesktopContainer as the central notification instance. It will trigger a userNotification but additionally show it in its labels, plus an icon that tells the user by color and image if this is a warning or just a success/result notification (in this case the megaphone and the green label).

Additionally, if user clicks on the pane, he will be shown the last max. 10 notifications in case he missed one.

2 Likes

That the same I do in my “Find Any File”. That’s the best solution IMO, because if the window is frontmost, the user will look at it and can see that message right there where he’s focused on.

Additionally, I optionally sound a “beep” when the search is finished, to get the user’s attention.

Maybe is different for mac users but in windows I had a good success with Toast notifications, this re bound to the app window and stay there, they stack if there are more than one notification, I use autoclose for trivial ones and some importat one are only closed when the user clicks on them.

Something like:

image

2 Likes

Sadly, it doesn’t seems like it, as the app needs to be code signed (see the following story below).

Since I recognise I should move to UNNotificationRequestMBS, I tried with a test project. In Xojo, I entered my developer ID in the sign section and tried to debug the app. I got this error when calling the RequestAuthorisation(7) method:

Error Domain=UNErrorDomain Code=1 “Notifications are not allowed for this application” UserInfo={NSLocalizedDescription=Notifications are not allowed for this application}

So I thought perhaps it’s because the app is only signed for debug, and I built the app. I code-signed and notarised it with AppWrapper (remember, it’s a test app, with merely the bundle ID set and an icon imported from another app; it’s weird to code-sign a test app). I still get the same error.

In AppWrapper, there’s no entitlement for notifications; just the notification type. Mine is set to “banner”. Also, in Settings (was “system preferences”), I can’t add the app to the list of apps allowed to send notifications.
Examples in the MBS plugins say your app must be code-signed, nothing more.

I feel I’ve tried everything I can think of. :man_shrugging:

I’m currently looking for Mac-only. Thanks anyway.

I didn’t do anything special. My app needs to be codesigned in the debugger anyways or I can’t use the app.

if SystemInformationMBS.isCatalina then
  
  if not UNUserNotificationCenterMBS.Available then Return
  Dim myNotification As New UNMutableNotificationContentMBS
  myNotification.title = theTitle
  myNotification.body = NotificationText
  
  Dim myTrigger As new UNTimeIntervalNotificationTriggerMBS(0.1, False)
  Dim myRequest As New UNNotificationRequestMBS(app.ExecutableFile.Name, myNotification, myTrigger)
  '' On Mojave and Catalina we could pass nil for the trigger, when sending the "immediate" option.  But we found we couldn't on Big Sur.
  '' Also, we cannot zero for the trigger, because it will throw an NSException.  So we settled for .1
  app.myNotificationCenter.addNotificationRequest(myRequest, Nil)
  
else
  
  if theNSNotification = nil then Return
  dim theNotifi as new NSUserNotificationMBS
  theNotifi.Title = theTitle
  theNotifi.informativeText = NotificationText
  theNSNotification.deliverNotification theNotifi
  
end if

Some followup – as I wrote above, I’m using UNUserNotificationCenterMBS and am getting notifications (banners) when my app is in front. I recently tried this on another Mac, and I did not receive the banner notification (although if I opened Notification Center I could see that the notification had indeed been received). After googling and playing around with System Preferences, I realized that had inadvertently turned on Focus for that Mac. Turning it off, or allowing my app to receive notifications when focus is on, restored the banner notifications when the app was in front. I don’t know if that was the case for the OP, but it’s a variable to consider.

Thanks for the thought, but it’s not my current issue. I receive notifications from other apps just fine.
The issue I’m having now is that my test app is not allowed to send notifications at all (and I can’t find a switch to allow that).

This is the beginning of my notification methode:

Var c As New UNUserNotificationCenterMBS

// get access by the user
If c <> Nil Then
  c.requestAuthorization(7)
End If

If you or one of your users have clicked on “No” in the dialog, you have to use the Terminal to reset the permisson database via tccutil:

tccutil reset All <your.bundle.id>

where <your.bundle.id> is replaced with something like “com.deltaworx.appname”