Plugin.LocalNotification icon indicating copy to clipboard operation
Plugin.LocalNotification copied to clipboard

iOS doesn't work when I add UseLocalNotification() to builder

Open zuzannaczaja opened this issue 3 years ago • 11 comments

Describe the bug My app is crashing when I add UseLocalNotification() function to builder in MauiProgram class.

To Reproduce Steps to reproduce the behavior:

  1. Create project.

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

     return builder.Build();
    

    }

  3. Run app.

  4. The application won't start.

Screenshots image

Platform (please complete the following information):

  • OS: iOS
  • Version 15.5

Smartphone (please complete the following information):

  • Device: iPhone 12 iOS 15.5
  • OS: iOS
  • Version 15.5

zuzannaczaja avatar Aug 04 '22 06:08 zuzannaczaja

@zuzannaczaja

can try below and remove UseLocalNotification();

public partial class AppDelegate :  MauiUIApplicationDelegate
{        
        protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp();

        public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {            
            LocalNotificationCenter.RequestNotificationPermissionAsync().GetAwaiter().GetResult();

            return base.FinishedLaunching(app, options);
        }

	public override void WillEnterForeground(UIApplication uiApplication)
        {
            LocalNotificationCenter.RequestNotificationPermissionAsync().GetAwaiter().GetResult();
            base.WillEnterForeground(uiApplication);
        }
}

thudugala avatar Aug 04 '22 06:08 thudugala

@zuzannaczaja

can try below and remove UseLocalNotification();

public partial class AppDelegate :  MauiUIApplicationDelegate
{        
        protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp();

        public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {            
            LocalNotificationCenter.RequestNotificationPermissionAsync().GetAwaiter().GetResult();

            return base.FinishedLaunching(app, options);
        }

	public override void WillEnterForeground(UIApplication uiApplication)
        {
            LocalNotificationCenter.RequestNotificationPermissionAsync().GetAwaiter().GetResult();
            base.WillEnterForeground(uiApplication);
        }
}

@thudugala Then there is the same problem

zuzannaczaja avatar Aug 04 '22 06:08 zuzannaczaja

I do not have access to mac now. Will be able to help debug the issue

is so try

public partial class AppDelegate :  MauiUIApplicationDelegate
{        
        protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp();

        public override async  bool FinishedLaunching(UIApplication app, NSDictionary options)
        {            
            await LocalNotificationCenter.RequestNotificationPermissionAsync();

            return base.FinishedLaunching(app, options);
        }

	public override async void WillEnterForeground(UIApplication uiApplication)
        {
            await LocalNotificationCenter.RequestNotificationPermissionAsync();
            base.WillEnterForeground(uiApplication);
        }
}

thudugala avatar Aug 04 '22 06:08 thudugala

I do not have access to mac now. Will be able to help debug the issue

is so try

public partial class AppDelegate :  MauiUIApplicationDelegate
{        
        protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp();

        public override async  bool FinishedLaunching(UIApplication app, NSDictionary options)
        {            
            await LocalNotificationCenter.RequestNotificationPermissionAsync();

            return base.FinishedLaunching(app, options);
        }

	public override async void WillEnterForeground(UIApplication uiApplication)
        {
            await LocalNotificationCenter.RequestNotificationPermissionAsync();
            base.WillEnterForeground(uiApplication);
        }
}

This code doesn't work image

I changed for this (without async and await) public override bool FinishedLaunching(UIApplication app, NSDictionary options) { LocalNotificationCenter.RequestNotificationPermissionAsync();

    return base.FinishedLaunching(app, options);
}

public override async void WillEnterForeground(UIApplication uiApplication)
{
    await LocalNotificationCenter.RequestNotificationPermissionAsync();
    base.WillEnterForeground(uiApplication);
}

but It doesn't work either

zuzannaczaja avatar Aug 04 '22 06:08 zuzannaczaja

@mphill will you be able to help?

thudugala avatar Aug 04 '22 22:08 thudugala

I have exactly the same issue, and the workarounds listed above don't work. I hope to see a fix soon, thanks :)

Hashemalrifai avatar Aug 17 '22 06:08 Hashemalrifai

@Hashemalrifai @zuzannaczaja Please try version 10.0.2

thudugala avatar Aug 19 '22 08:08 thudugala

@Hashemalrifai @zuzannaczaja Please try version 10.0.2

I encountered the same issue. Updating to version 10.0.2 fixes the issue, but the notification doesn't appear at all on the iOS emulator. However, it does work on the Android emulator.

constantinginga avatar Aug 19 '22 08:08 constantinginga

@constantinginga

can try below and remove UseLocalNotification();

public partial class AppDelegate :  MauiUIApplicationDelegate
{        
        protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp();

        public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {            
            LocalNotificationCenter.RequestNotificationPermission();

            return base.FinishedLaunching(app, options);
        }

	public override void WillEnterForeground(UIApplication uiApplication)
        {
            LocalNotificationCenter.ResetApplicationIconBadgeNumber(uiApplication);
            base.WillEnterForeground(uiApplication);
        }
}

thudugala avatar Aug 24 '22 20:08 thudugala

@constantinginga

can try below and remove UseLocalNotification();

public partial class AppDelegate :  MauiUIApplicationDelegate
{        
        protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp();

        public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {            
            LocalNotificationCenter.RequestNotificationPermission();

            return base.FinishedLaunching(app, options);
        }

	public override void WillEnterForeground(UIApplication uiApplication)
        {
            LocalNotificationCenter.ResetApplicationIconBadgeNumber(uiApplication);
            base.WillEnterForeground(uiApplication);
        }
}

Doesn't seem to work, the notification still doesn't show up.

constantinginga avatar Aug 25 '22 07:08 constantinginga

@constantinginga can try below and remove UseLocalNotification();

public partial class AppDelegate :  MauiUIApplicationDelegate
{        
        protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp();

        public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {            
            LocalNotificationCenter.RequestNotificationPermission();

            return base.FinishedLaunching(app, options);
        }

	public override void WillEnterForeground(UIApplication uiApplication)
        {
            LocalNotificationCenter.ResetApplicationIconBadgeNumber(uiApplication);
            base.WillEnterForeground(uiApplication);
        }
}

Doesn't seem to work, the notification still doesn't show up.

I have the same problem.

zuzannaczaja avatar Aug 31 '22 09:08 zuzannaczaja

Still not fixed?

claus-lysholm avatar Nov 15 '22 07:11 claus-lysholm

Try version 10.0.3

thudugala avatar Nov 29 '22 09:11 thudugala