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

m4t*_*mus 4 xamarin.ios xamarin xamarin.forms

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

好像它像UIUserNotificationSettings.GetSettingsForTypes(UIUserNotificationType.Sound,new NSSet()); 但是我不确定如何使用NSSet读取设置。

Sus*_*ver 5

UserNotifications.framework被在IOS 10添加和替换UIUserNotification

您可以UNUserNotificationCenter用来确定启用了什么:

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