如何在Swift 3中获取通知授权状态? [英] How to get notification authorization status in swift 3?

查看:358
本文介绍了如何在Swift 3中获取通知授权状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在iOS 11中检查UNUserNotificationCenter的当前授权状态?我一直在寻找一段时间,发现了一些代码,但是它并没有在Swift 3中出现,某些功能在iOS 10中已被弃用.

How can I check UNUserNotificationCenter for current authorization status in iOS 11? I've been looking for a while and found some code but it's not in swift 3 and some of functions were deprecated in iOS 10. Can anyone help?

推荐答案

好吧,我找到了它:

let center = UNUserNotificationCenter.current()
center.getNotificationSettings { (settings) in
    if(settings.authorizationStatus == .authorized)
    {
        print("Push authorized")
    }
    else
    {
        print("Push not authorized")
    }
}

通过以下方式进行编码:库巴

code by: Kuba

这篇关于如何在Swift 3中获取通知授权状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆