-
Notifications
You must be signed in to change notification settings - Fork 85
/
PushNotificationsAuthorization.swift
44 lines (36 loc) · 1.55 KB
/
PushNotificationsAuthorization.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
//
// 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()
}
}
}
}
}