【发布时间】:2017-10-10 10:13:18
【问题描述】:
在我的应用中,我希望能够检查用户是否启用了通知。在 iOS 10 中,我使用委托中的检查来执行此操作。
此检查现已弃用,我想对其进行更新,但我不知道在 iOS 11 中要使用什么。
弃用警告如下:
currentUserNotificationSettings' 在 iOS 10.0 中已弃用:使用 UserNotifications 框架的 -[UNUserNotificationCenter getNotificationSettingsWithCompletionHandler:] 和 -[UNUserNotificationCenter getNotificationCategoriesWithCompletionHandler:]
我尝试在此警告的帮助下更新代码,但我无法弄清楚。
如果任何人都可以建议获得这样的支票,那将有很大帮助。我在 iOS 10 上使用的代码如下,谢谢。
let notificationType = UIApplication.shared.currentUserNotificationSettings!.types
if notificationType == [] {
print("Notifications are NOT enabled")
} else {
print("Notifications are enabled")
}
【问题讨论】:
标签: ios cocoa-touch usernotifications