Missing AskPermission & exceptions
It seems that 'Plugin.LocalNotification.NotificationCenter.AskPermission();' is missing, I would like to ask for permission when user activates a toggle in the App, it actually works as mentioned when I create a Notification, but it would be nice to also be able to ask for the permission as described in documentation, I also can't find how to get the user permission status in order to be able to tell the user to activate the permission if he did decline the approval when he was asked for, creating a new notification when user has not granted access is not returning any status or error, how can I see the response of a new notification, if it was success, if it threw an exception because user does not allow local notifications etc.. it would be nice to have this in order to be able to give some feedback to the user.
@PonyOny can you please attach a sample project?
It seems that 'Plugin.LocalNotification.NotificationCenter.AskPermission();' is missing, I would like to ask for permission when user activates a toggle in the App, it actually works as mentioned when I create a Notification, but it would be nice to also be able to ask for the permission as described in documentation, I also can't find how to get the user permission status in order to be able to tell the user to activate the permission if he did decline the approval when he was asked for, creating a new notification when user has not granted access is not returning any status or error, how can I see the response of a new notification, if it was success, if it threw an exception because user does not allow local notifications etc.. it would be nice to have this in order to be able to give some feedback to the user.
Hello, my workaround for this is that if the user declines the first notification permission and may want to re-activate, then I will redirect the user to the application's settings using Xamarin Essentials' AppInfo.ShowSettingsUI() method. Hope this helps.
Hi, thanks, I have already a work around.. but I was expecting that the plugin could manage this scenario, I have created a custom service to manage the permissions and the current status of the Notifications access so i can know if he has granted permission or if he declined to show as you mentioned a custom dialog that will take to the app settings.
public interface IDeviceService
{
bool AreNotificationsAllowed();
Task<bool> RequestNotificationsPermission();
void OpenSettings();
}
IOS:
public class DeviceService : IDeviceService
{
public bool AreNotificationsAllowed()
{
var settings = UIApplication.SharedApplication.CurrentUserNotificationSettings.Types;
return settings != UIUserNotificationType.None;
}
public void OpenSettings()
{
var url = new NSUrl($"app-settings:");
UIApplication.SharedApplication.OpenUrl(url);
}
public async Task<bool> RequestNotificationsPermission()
{
var status = await UNUserNotificationCenter.Current.RequestAuthorizationAsync(UNAuthorizationOptions.Alert | UNAuthorizationOptions.Badge | UNAuthorizationOptions.Sound);
return status.Item1;
}
}
@PonyOny can you try 9.2.1-preview01
@PonyOny, please try 10.0.0-preview02
I see the issue. AskPermission is only defined in the the project that targets iOS. As a result this can not be called in the Xamarin head project.
I think AskPermission should be moved to INotificationService. This would allow you to setup notification outside of the AppDelegate.
Additionally, Android 13 will be adding this:
https://developer.android.com/about/versions/13/changes/notification-permission#user-choice
Try version 10.0.3