PushHandler
public protocol PushHandler : AnyObject, Sendable
Protocol that defines the required behaviour for push notification handlers.
A push handler is responsible for determining whether it can process incoming push notifications for a specific platform, parsing the received payload, and delegating registration and response operations to the appropriate network responder.
Implementations may interact with platform-specific services (e.g., PingAM) and are expected to provide detailed logging and error handling. All methods should be thread-safe and support concurrent usage from Swift concurrency contexts.
-
Check if this handler can process the given message data. This method should inspect the map data (typically the push notification payload) to determine if it can be handled by this handler.
Declaration
Swift
func canHandle(messageData: [String : Any]) -> BoolParameters
messageDataThe message data as a map, usually received from UNNotification userInfo.
Return Value
True if this handler can process the message data, false otherwise.
-
Check if this handler can process the given message in string format. This method should inspect the message string to determine if it can be handled by this handler. It should return true if the handler can process the message, and false otherwise.
Declaration
Swift
func canHandle(message: String) -> BoolParameters
messageThe message data as a string, typically a JWT or JSON string.
Return Value
True if this handler can process the message, false otherwise.
-
Parse the message data received from the push service. It should extract relevant information such as notification type, message content, and any additional parameters. It should return a map of parsed data that maps to the expected structure for the PushNotification.
Throws
PushError.messageParsingFailedif parsing fails.Declaration
Swift
func parseMessage(messageData: [String : Any]) throws -> [String : Any]Parameters
messageDataThe message data to parse. Usually a map containing the raw data from the push service. On iOS, this would typically come from UNNotificationRequest userInfo.
Return Value
A map of parsed data.
-
Parse the message received as a string. It should extract relevant information from the string message (typically a JWT or JSON string) and return a map of parsed data that maps to the expected structure for the PushNotification.
Throws
PushError.messageParsingFailedif parsing fails.Declaration
Swift
func parseMessage(message: String) throws -> [String : Any]Parameters
messageThe message data as a string to parse.
Return Value
A map of parsed data.
-
sendApproval(credential:Asynchronousnotification: params: ) Send to the server an approval response for a notification that was received. How the approval is sent depends on the platform and the implementation of this handler.
Throws
PushError.networkFailureif the network request fails.Declaration
Swift
func sendApproval( credential: PushCredential, notification: PushNotification, params: [String: Any] ) async throws -> BoolParameters
credentialThe credential to use for the response.
notificationThe notification to approve.
paramsAdditional parameters.
Return Value
True if the approval was sent successfully, false otherwise.
-
sendDenial(credential:Asynchronousnotification: params: ) Send a denial response for a notification. How the denial is sent depends on the platform and the implementation of this handler.
Throws
PushError.networkFailureif the network request fails.Declaration
Swift
func sendDenial( credential: PushCredential, notification: PushNotification, params: [String: Any] ) async throws -> BoolParameters
credentialThe credential to use for the response.
notificationThe notification to deny.
paramsAdditional parameters.
Return Value
True if the denial was sent successfully, false otherwise.
-
setDeviceToken(credential:AsynchronousdeviceToken: params: ) Register or update the device token. This is typically called when the device token changes.
Throws
PushError.networkFailureif the network request fails.Declaration
Swift
func setDeviceToken( credential: PushCredential, deviceToken: String, params: [String: Any] ) async throws -> BoolParameters
credentialThe credential to register or update.
deviceTokenThe device token.
paramsAdditional parameters.
Return Value
True if was successful, false otherwise.
-
register(credential:Asynchronousparams: ) Register a new push credential with the server, if this is required by the platform. The parameters may include additional information or any other relevant data that the server needs to process the registration.
Throws
PushError.networkFailureif the network request fails.Declaration
Swift
func register( credential: PushCredential, params: [String: Any] ) async throws -> BoolParameters
credentialThe credential to register.
paramsAdditional parameters for registration including messageId.
Return Value
True if the registration was successful, false otherwise.
View on GitHub