Skip to content

Commit

Permalink
Fix permission request (#2046)
Browse files Browse the repository at this point in the history
Task/Issue URL: https://app.asana.com/0/0/1206319918056750/f
Tech Design URL:
CC:

**Description**:
Ask for notification permission before sending notifications. This is to
fix a bug where the notification permission would only be requested
after the first scan step.

The notification being sent right after the permission is requested
might not be sent, which is fine.
  • Loading branch information
Bunn authored Jan 10, 2024
1 parent 08ba477 commit f04a621
Showing 1 changed file with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,12 @@ public class DefaultDataBrokerProtectionUserNotificationService: NSObject, DataB

public func requestNotificationPermission() {
guard areNotificationsEnabled else { return }

userNotificationCenter.requestAuthorization(options: [.alert]) { _, _ in }
requestNotificationPermissionIfNecessary()
}

private func sendNotification(_ notification: UserNotification, afterDays days: Int? = nil) {
requestNotificationPermissionIfNecessary()

let notificationContent = UNMutableNotificationContent()
notificationContent.title = notification.title
notificationContent.body = notification.message
Expand Down Expand Up @@ -96,6 +97,14 @@ public class DefaultDataBrokerProtectionUserNotificationService: NSObject, DataB
}
}

private func requestNotificationPermissionIfNecessary() {
userNotificationCenter.getNotificationSettings { [weak self] settings in
if settings.authorizationStatus == .notDetermined {
self?.userNotificationCenter.requestAuthorization(options: [.alert]) { _, _ in }
}
}
}

public func sendFirstScanCompletedNotification() {
guard areNotificationsEnabled else { return }

Expand Down

0 comments on commit f04a621

Please sign in to comment.