Skip to content

Commit

Permalink
Fix runtime crash in UBPushManager
Browse files Browse the repository at this point in the history
  • Loading branch information
ubfelix committed Oct 7, 2024
1 parent 4f75984 commit 9491bd4
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions Sources/UBPush/UBPushManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ open class UBPushManager: NSObject {
static let logger = Logger(subsystem: "ch.ubique.ubkit", category: "PushManager")

/// Closure to handle the permission request result
public typealias PermissionRequestCallback = (PermissionRequestResult) -> Void
public typealias PermissionRequestCallback = @Sendable (PermissionRequestResult) -> Void

/// :nodoc:
@MainActor
Expand Down Expand Up @@ -172,11 +172,10 @@ open class UBPushManager: NSObject {
/// Requests APNS token (if .authorized)
///
private func registerForPushNotification() {
UNUserNotificationCenter.current().getNotificationSettings { settings in
UNUserNotificationCenter.current().getNotificationSettings { @Sendable settings in
if settings.authorizationStatus == .authorized {
UNUserNotificationCenter.current().setNotificationCategories(self.pushHandler.notificationCategories)

DispatchQueue.main.async {
Task { @MainActor in
UNUserNotificationCenter.current().setNotificationCategories(self.pushHandler.notificationCategories)
UIApplication.shared.registerForRemoteNotifications()
}
}
Expand All @@ -202,7 +201,7 @@ open class UBPushManager: NSObject {
let currentPushRequest = latestPushRequest

let options = makeAuthorizationOptions(includingCritical: includingCritical, includingNotificationSettings: includingNotificationSettings)
UNUserNotificationCenter.current().requestAuthorization(options: options) { granted, _ in
UNUserNotificationCenter.current().requestAuthorization(options: options) { @Sendable granted, _ in

guard granted else {
DispatchQueue.main.async {
Expand All @@ -223,9 +222,8 @@ open class UBPushManager: NSObject {
}
}

UNUserNotificationCenter.current().setNotificationCategories(self.pushHandler.notificationCategories)

DispatchQueue.main.async {
Task { @MainActor in
UNUserNotificationCenter.current().setNotificationCategories(self.pushHandler.notificationCategories)
UIApplication.shared.registerForRemoteNotifications()
}
}
Expand Down

0 comments on commit 9491bd4

Please sign in to comment.