mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2025-08-12 06:26:36 +00:00
more work on notifications
This commit is contained in:
@@ -10,6 +10,10 @@ import UIKit
|
||||
import Account
|
||||
import UserNotifications
|
||||
|
||||
extension Notification.Name {
|
||||
static let NotificationPreferencesDidUpdate = Notification.Name("NotificationPreferencesDidUpdate")
|
||||
}
|
||||
|
||||
class NotificationsTableViewCell: UITableViewCell {
|
||||
|
||||
@IBOutlet weak var notificationsSwitch: UISwitch!
|
||||
@@ -45,11 +49,17 @@ class NotificationsTableViewCell: UITableViewCell {
|
||||
notificationsImageView.layer.cornerRadius = 4
|
||||
}
|
||||
|
||||
|
||||
/// Used for notification permissions only.
|
||||
/// - Parameter status: `UNAuthorizationStatus`
|
||||
func configure(_ status: UNAuthorizationStatus) {
|
||||
notificationsSwitch.isOn = (status == .authorized) ? true : false
|
||||
if status == .denied { notificationsSwitch.isEnabled = false }
|
||||
notificationsSwitch.isOn = (status == .authorized || status == .provisional) ? true : false
|
||||
if status == .denied || status == .authorized || status == .provisional { notificationsSwitch.isEnabled = false }
|
||||
if status == .notDetermined {
|
||||
notificationsSwitch.addTarget(self, action: #selector(requestNotificationPermissions(_:)), for: .touchUpInside)
|
||||
}
|
||||
notificationsLabel.text = NSLocalizedString("Enable Notifications", comment: "")
|
||||
notificationsImageView.image = UIImage(systemName: "bell")
|
||||
notificationsImageView.image = UIImage(systemName: "app.badge")
|
||||
notificationsImageView.layer.cornerRadius = 4
|
||||
}
|
||||
|
||||
@@ -66,5 +76,13 @@ class NotificationsTableViewCell: UITableViewCell {
|
||||
}
|
||||
}
|
||||
|
||||
@objc
|
||||
private func requestNotificationPermissions(_ sender: Any) {
|
||||
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .badge, .sound]) { success, error in
|
||||
NotificationCenter.default.post(name: .NotificationPreferencesDidUpdate, object: nil)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user