Xamarin iOS: check if notification is enabled

I am trying to find out if the user has sound / vibration for notifications in iOS settings. I use Xamarin forms, but Xamarin.iOS will also be acceptable.

It seems to be something like UIUserNotificationSettings.GetSettingsForTypes (UIUserNotificationType.Sound, new NSSet ()); but I'm not sure what to do with NSSet to read the settings after.

+4
source share
1 answer

UserNotifications.frameworkwas added in iOS 10 and replaced UIUserNotification.

You can use UNUserNotificationCenterto determine what is included:

var notificationSettings = await UNUserNotificationCenter.Current.GetNotificationSettingsAsync();
switch (notificationSettings.SoundSetting)
{
    case UNNotificationSetting.Disabled:
        break;
    case UNNotificationSetting.Enabled:
        break;
    case UNNotificationSetting.NotSupported; // Simulator...
        break;
}
+4
source

Source: https://habr.com/ru/post/1684680/


All Articles