Skip to content

Commit

Permalink
Merge pull request #117 from UbiqueInnovation/feature/provisional-push
Browse files Browse the repository at this point in the history
  • Loading branch information
maerki authored Jan 30, 2025
2 parents 632555a + 92d5882 commit f106519
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
1 change: 0 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ let package = Package(
],
dependencies: [
.package(url: "https://github.com/UbiqueInnovation/ios-local-networking.git", from: "1.0.2"),
.package(url: "https://github.com/apple/swift-syntax", .upToNextMajor(from: "509.0.0")),
],
targets: [
.target(
Expand Down
19 changes: 17 additions & 2 deletions Sources/UBPush/UBPushManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ open class UBPushManager: NSObject {
/// - callback: The callback for handling the result of the request
public func requestPushPermissions(includingCritical: Bool = false,
includingNotificationSettings: Bool = false,
provisional: Bool = false,
providesAppSettings: Bool = false,
callback: @escaping PermissionRequestCallback) {
if let previousCallback = permissionRequestCallback {
Self.logger.error("Tried to request push permissions while other request pending")
Expand All @@ -200,7 +202,12 @@ open class UBPushManager: NSObject {
latestPushRequest += 1
let currentPushRequest = latestPushRequest

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

guard granted else {
Expand Down Expand Up @@ -230,7 +237,7 @@ open class UBPushManager: NSObject {
}

/// :nodoc:
private func makeAuthorizationOptions(includingCritical: Bool, includingNotificationSettings: Bool) -> UNAuthorizationOptions {
private func makeAuthorizationOptions(includingCritical: Bool, includingNotificationSettings: Bool, provisional: Bool, providesAppSettings: Bool) -> UNAuthorizationOptions {
var options: UNAuthorizationOptions = [.alert, .badge, .sound]

if includingCritical {
Expand All @@ -241,6 +248,14 @@ open class UBPushManager: NSObject {
options.insert(.providesAppNotificationSettings)
}

if provisional {
options.insert(.provisional)
}

if providesAppSettings {
options.insert(.providesAppNotificationSettings)
}

return options
}

Expand Down

0 comments on commit f106519

Please sign in to comment.