mirror of
https://github.com/confirmedcode/Lockdown-iOS.git
synced 2025-12-16 12:00:16 +01:00
45 lines
1.6 KiB
Swift
45 lines
1.6 KiB
Swift
//
|
|
// PushNotificationsAuthorize.swift
|
|
// Lockdown
|
|
//
|
|
// Created by Oleg Dreyman on 28.05.2020.
|
|
// Copyright © 2020 Confirmed Inc. All rights reserved.
|
|
//
|
|
|
|
import UIKit
|
|
import UserNotifications
|
|
import CocoaLumberjackSwift
|
|
|
|
extension PushNotifications {
|
|
|
|
enum Authorization {
|
|
|
|
static let kUserAuthorizedPrefix = "LockdownNotificationsUserAuthorizedCategory"
|
|
|
|
enum Status {
|
|
case authorized
|
|
case notAuthorized
|
|
}
|
|
|
|
static func getUserWantsNotificationsEnabled(forCategory category: PushNotifications.Category) -> Bool {
|
|
return defaults.bool(forKey: kUserAuthorizedPrefix + category.rawValue)
|
|
}
|
|
|
|
static func getUserWantsNotificationsEnabledForAnyCategory() -> Bool {
|
|
return getUserWantsNotificationsEnabled(forCategory: .weeklyUpdate)
|
|
}
|
|
|
|
static func setUserWantsNotificationsEnabled(_ userWantsNotificationsEnabled: Bool, forCategory category: PushNotifications.Category) {
|
|
defaults.set(userWantsNotificationsEnabled, forKey: kUserAuthorizedPrefix + category.rawValue)
|
|
if category == .weeklyUpdate {
|
|
if userWantsNotificationsEnabled {
|
|
PushNotifications.shared.userDidAuthorizeWeeklyUpdate()
|
|
} else {
|
|
DDLogInfo("Weekly updates notifications are turned off; removing all pending notifications")
|
|
PushNotifications.shared.removeAllPendingNotifications()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|