Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Cover image for App Settings in .NET MAUI - Notifications
Victor Hugo Garcia
Victor Hugo Garcia

Posted on • Edited on

     

App Settings in .NET MAUI - Notifications

In this article, I'm going to show you how to validate if the user enabled or disabled the app notifications in .NET MAUI for Android and iOS.


Create a static class NotificationsHelper

publicstaticboolAreDeviceNotificationsEnabled(){#if ANDROIDreturnAndroidX.Core.App.NotificationManagerCompat.From(Platform.CurrentActivity).AreNotificationsEnabled();#elif IOSvarsettings=UIKit.UIApplication.SharedApplication.CurrentUserNotificationSettings.Types;returnsettings!=UIKit.UIUserNotificationType.None;#endif}
Enter fullscreen modeExit fullscreen mode

Validate

It is a good practice to help the users by asking them if they want to open the app settings, so they can enable the notifications.

if(!AreDeviceNotificationsEnabled()){if(showAlert){varresult=awaitApplication.Current.MainPage.DisplayAlert("Enable Notifications","Your notifications system are currently turned off","Go to Settings","Cancel");if(result){AppInfo.ShowSettingsUI();}}}
Enter fullscreen modeExit fullscreen mode

Conclusion

In .NET MAUI it is really cool how easy you can implement a static method that allows to execute code based on each platform. Of course if you prefer to avoid the declarative conditionals you can always use the.ios.cs and.android.cs file class naming convention.

Thanks for reading! Follow me on Twitter@ivictorhugo

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Passionate software engineer with a love for design and an unwavering commitment to enjoying life to the fullest.
  • Location
    Austin, Texas
  • Education
    Instituto Tecnológico de Ciudad Guzman
  • Work
    Software Engineer at simplea.com
  • Joined

More fromVictor Hugo Garcia

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp