Xamarin iOS:检查是否启用了通知声音

我试图找出用户是否在iOS设置中有通知的声音/振动.我正在使用Xamarin表单,但Xamarin.iOS也是可以接受的.

看起来像它的东西
UIUserNotificationSettings.GetSettingsForTypes(UIUserNotificationType.Sound,new NSSet());
但我不确定如何处理NSSet后读取设置.

最佳答案
在iOS 10中添加了UserNotifications.framework并替换了UIUserNotification.

您可以使用UNUserNotificationCenter来确定启用的内容:

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

转载注明原文:Xamarin iOS:检查是否启用了通知声音 - 代码日志