Plugin.LocalNotification doesn't build in Release Mode

Viewed 49

I try to add LocalNotification to the application, everything works in Debug mode, but when I change to Release mode, notifications do not work. Anyone know how to deal with it?

using Plugin.LocalNotification;

namespace TestNotif;

public static class MauiProgram
{
    public static MauiApp CreateMauiApp()
    {
        var builder = MauiApp.CreateBuilder();
        builder
            .UseMauiApp<App>()
            .UseLocalNotification()
            .ConfigureFonts(fonts =>
            {
                fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
                fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
            });

        

        return builder.Build();
    }
}

I got this error CS1061:

Severity Code Description Project File Line Suppression State Error CS1061 'MauiAppBuilder' does not contain a definition for 'UseLocalNotification' and no accessible extension method 'UseLocalNotification' accepting a first argument of type 'MauiAppBuilder' could be found (are you missing a using directive or an assembly reference?) TestNotif (net6.0-maccatalyst), TestNotif (net6.0-windows10.0.19041.0) C:\Users---\source\repos\TestNotif\TestNotif\MauiProgram.cs 14 Active

using Plugin.LocalNotification;
using System;

namespace TestNotif;

public partial class MainPage : ContentPage
{
    int count = 0;
    

    public MainPage()
    {
        InitializeComponent();
        NotificationGet();
    }

    public async void Button_Clicked(object sender, EventArgs e)
    {
        var notification6 = new NotificationRequest
        {
            BadgeNumber = 1,
            Description = "Test Description",
            Title = "Notification!",
            ReturningData = "Dummy Data",
            NotificationId = 1327,
            Schedule =
            {


                NotifyTime = DateTime.Now.AddSeconds(5)
            }

        };
        await LocalNotificationCenter.Current.Show(notification6);
    }
1 Answers

Fix #1: Only build for Android, to avoid errors when Maui attempts to build release for MacCatalyst and Windows:

  • Rt-click your Maui project, "Properties".
  • Application > General, find "iOS Targets > Target the iOS platform: Enable targeting of the iOS platform. UNCHECK.
  • Similarly find and UNCHECK: Windows Targets > Target ..: Enable targetting of the Windows platform.

Fix #2: Notifications don't work on Android:

  • Test on an actual device, not on an emulator.

If after both of these, it still doesn't work, then contact author of that plug-in for help.

Related