'How to remove notification in xamarin ios?

I deleted the notification text, but the old text still shows

        var content = new UNMutableNotificationContent(); 
        content.Title = "";
        content.Body = "";  ---- I deleted the old text from here but it still shows this notification on my phone
        content.Badge = 1;
        content.CategoryIdentifier = "message";
        content.Sound = UNNotificationSound.Default;

using the command ctrl shift + F I checked if the text that was in the body was anywhere in the project but there isn't. What could be the reason?



Solution 1:[1]

In your iOS project add this line after LoadApplication(new App());

UNUserNotificationCenter.Current.Delegate = new UserNotificationCenterDelegate();

An create a class named UserNotificationCenterDelegate

Inside that class

        public class UserNotificationCenterDelegate : UNUserNotificationCenterDelegate
        {
             public override void WillPresentNotification(UNUserNotificationCenter center, UNNotification notification, Action<UNNotificationPresentationOptions> completionHandler)
             {
//Will silence all notifications
completionHandler(UNNotificationPresentationOptions.None);
//Will play just the notification sound without showing a notification
completionHandler(UNNotificationPresentationOptions.None | UNNotificationPresentationOptions.Sound);
//Will show a banner and play notification sound
completionHandler(UNNotificationPresentationOptions.None | UNNotificationPresentationOptions.Sound);
              }
        }

Solution 2:[2]

We can create a new notification with the desired parameters modified (such as a new trigger time) and add it to the system with the same Request Identifier as the Notification that needs to be modified.

using UserNotifications;
...

// Rebuild notification
var content = new UNMutableNotificationContent ();
content.Title = "Notification Title";
content.Subtitle = "Notification Subtitle";
content.Body = "This is the message body of the notification.";
content.Badge = 1;

// New trigger time
var trigger = UNTimeIntervalNotificationTrigger.CreateTrigger (10, false);

// ID of Notification to be updated
var requestID = "sampleRequest";
var request = UNNotificationRequest.FromIdentifier (requestID, content, trigger);

// Add to system to modify existing Notification
UNUserNotificationCenter.Current.AddNotificationRequest (request, (err) => {
    if (err != null) {
        // Do something with error...
    }
});

For already delivered Notifications, the existing Notification will get updated and promoted to the top of the list on the Home and Lock screens and in the Notification Center if it has already been read by the user.

Refer to

https://docs.microsoft.com/en-us/xamarin/ios/platform/user-notifications/enhanced-user-notifications?tabs=macos#updating-an-existing-notification.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Mario M Greer
Solution 2 ColeX - MSFT