HomeiOS DevelopmentRequest Notifications Permission in a .Web MAUI App for IOS

Request Notifications Permission in a .Web MAUI App for IOS


This labored on my Scorching Restart-deployed IOS app: in Platforms/iOS/AppDelegate.cs, use the next code derived from Dima Ordenov’s MauiSamples

utilizing UIKit;
utilizing UserNotifications;

...

public override bool FinishedLaunching(UIApplication utility, NSDictionary launchOptions)
{
    RegisterForRemoteNotifications(utility);

    return base.FinishedLaunching(utility, launchOptions);
}

/// <abstract>
/// Reqeust permission for notifications
/// </abstract>
/// <param identify="utility"></param>
/// <remarks>from https://github.com/DimaOrdenov/MauiSamples/blob/fundamental/MauiPushNotifications/Platforms/iOS/AppDelegate.cs</remarks>
non-public void RegisterForRemoteNotifications(UIApplication utility)
{
    UNUserNotificationCenter.Present.RequestAuthorization(
        UNAuthorizationOptions.Alert | UNAuthorizationOptions.Badge | UNAuthorizationOptions.Sound,
        (isSuccess, error) =>
        {
            if (error != null)
            {
                // no op, not going to do something about this for now
            }
        });

    utility.RegisterForRemoteNotifications();
}

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments