【问题标题】:User Notification Center get Authorization Options Swift 3/4 ios10/11用户通知中心获取授权选项 Swift 3/4 ios10/11
【发布时间】:2018-07-03 13:54:48
【问题描述】:

对于低于 10 的 iOS,我们曾经拥有获取用户允许的通知类型(.alert、.badge 等)的属性。我们使用了这段代码:

UIApplication.shared.currentUserNotificationSettings?.types

但它现在已被弃用。

问题:

除了在 ios10/11 上使用 UNUserNotificationCenter 外,我们如何做同样的事情? 有没有等效的方法?

考虑一下:已弃用的方法仍然有效,但我们不知道苹果是否有一天会取消它。

提前致谢!

【问题讨论】:

    标签: ios notifications uilocalnotification localnotification unusernotificationcenter


    【解决方案1】:

    您仍然可以通过以下方式获取通知设置:

    UNUserNotificationCenter.current().getNotificationSettings { settings in
    
        if settings.alertSetting == .enabled {
            //alert is enabled
        }
    
    }
    

    正如apple doc中提到的那样

    当该属性的值为 UNNotificationSetting.enabled 时, 应用被授权显示警报。

    【讨论】:

    • 谢谢:)) 在你回答之前就已经弄清楚了 :))
    猜你喜欢
    • 1970-01-01
    • 2017-02-05
    • 2017-01-08
    • 1970-01-01
    • 1970-01-01
    • 2023-03-28
    • 1970-01-01
    • 1970-01-01
    • 2018-06-14
    相关资源
    最近更新 更多