在我的應用中,我希望能夠檢查用戶是否啓用了通知。在iOS 10中,我使用委託中的檢查來完成此操作。檢查UILocalNotification棄用後是否啓用用戶通知
此檢查現在已經過時,我希望更新它,但我想不出在iOS的11
棄用警告如下的內容:
currentUserNotificationSettings'被棄用iOS的10.0:使用 UserNotifications Framework的 - [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的10處理呢? – Josh
您必須通過'currentUserNotificationSettings'方法從** UIApplication.shared **中獲取'UIUserNotificationSettings'對象。 – McNight
非常感謝:) – Josh