How to Send Toaster like Notification in MAUI MAC OS Application ?

Sanket Vinod Solanki 30 Reputation points
2023-11-18T04:58:01.9166667+00:00

Hi,

We have developed MAUI Application for Windows and MACOS, and we have Successfully implemented Toaster notification ( side pop up balloon like notifications) for Windows using https://learn.microsoft.com/en-us/windows/apps/design/shell/tiles-and-notifications/send-local-toast?tabs=uwp

How do we implement Balloon / Toaster notification for MAUI MacOS (mac catalyst).

Developer technologies | .NET | .NET MAUI
Developer technologies | C#
{count} votes

1 answer

Sort by: Most helpful
  1. Anonymous
    2023-11-20T08:45:40.0166667+00:00

    Hello,

    This Microsoft.Toolkit.Uwp.Notifications nuget package apply for the WPF, UWP, WinForms, console, you cannot use it in the mac catalyst.

    if you want to pusho notification in the Mac catalyst, you can use native iOS api: UNUserNotificationCenter, you can refer to the following code.

    #if MACCATALYST
                var content = new UserNotifications.UNMutableNotificationContent
                {
                    Title = "Warning! ",
                    Body = "This is an alert!",
                    CategoryIdentifier = "WARNING_ALERT",
                    Sound = UserNotifications.UNNotificationSound.DefaultCriticalSound
                };
    
    
               var trigger = UserNotifications.UNTimeIntervalNotificationTrigger.CreateTrigger(5, false);
    
    
               var request = UserNotifications.UNNotificationRequest.FromIdentifier("ALERT_REQUEST", content, trigger);
    
    
               UserNotifications.UNUserNotificationCenter.Current.AddNotificationRequest(request, (error) =>
                {
                    if (error != null)
                    {
                        Console.WriteLine("Error: " + error);
                    }
                });
    #endif
    

    Best Regards,

    Leon Lu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.