39 lines
1.6 KiB
Swift
39 lines
1.6 KiB
Swift
//
|
|
// RegisterPushNotificationActionHandler.swift
|
|
// MobileFirstFramework
|
|
//
|
|
// Created by Digvijay Mallegowda Chinnappa on 12/15/21.
|
|
// Copyright © 2021 Verizon Wireless. All rights reserved.
|
|
//
|
|
|
|
import Foundation
|
|
import CoreMedia
|
|
import MVMCore
|
|
|
|
public struct RegisterPushNotificationActionHandler: MVMCoreActionHandlerProtocol {
|
|
public init(){}
|
|
public func execute(with model: ActionModelProtocol, delegateObject: DelegateObject?, additionalData: [AnyHashable : Any]?) async throws {
|
|
guard let model = model as? ActionRegisterPushNotificationModel else { return }
|
|
try await withCheckedThrowingContinuation { continuation in
|
|
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .badge, .sound], completionHandler: { granted, error in
|
|
guard var completionAction = model.completionAction else {
|
|
continuation.resume()
|
|
return
|
|
}
|
|
var extraParameter = completionAction.extraParameters ?? [:]
|
|
extraParameter["granted"] = JSONValue(booleanLiteral: granted)
|
|
completionAction.extraParameters = extraParameter
|
|
let action = completionAction
|
|
Task {
|
|
do {
|
|
try await (delegateObject?.actionDelegate as? ActionDelegateProtocol)?.performAction(with: action, additionalData: additionalData, delegateObject: delegateObject)
|
|
continuation.resume()
|
|
} catch {
|
|
continuation.resume(throwing: error)
|
|
}
|
|
}
|
|
})
|
|
} as Void
|
|
}
|
|
}
|