【问题标题】:Xamarin iOS: Check if notification sound is enabledXamarin iOS:检查是否启用了通知声音
【发布时间】:2017-08-29 16:32:11
【问题描述】:

我正在尝试确定用户是否在 iOS 设置中为通知打开了声音/振动。我正在使用 Xamarin 表单,但 Xamarin.iOS 也可以接受。

好像是这样的 UIUserNotificationSettings.GetSettingsForTypes(UIUserNotificationType.Sound, new NSSet()); 但我不确定如何处理 NSSet 来读取设置。

【问题讨论】:

    标签: xamarin xamarin.ios xamarin.forms


    【解决方案1】:

    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;
    }
    

    【讨论】:

    • 这个代码会抛出一个异常是任何低于 10 的 iOS 所以一定要抓住它!
    猜你喜欢
    • 1970-01-01
    • 2014-11-21
    • 2020-04-27
    • 1970-01-01
    • 2020-03-13
    • 1970-01-01
    • 1970-01-01
    • 2016-12-01
    • 1970-01-01
    相关资源
    最近更新 更多