DefaultNotificationHelper
open class DefaultNotificationHelper : NotificationHelper
NotificationHelper
with default implementations.
-
Handler of Basic (non-rich) Push Notifications
Declaration
Swift
public var pushHandler: PushHandler
-
Handler of Rich Push Notification Quick Actions
Declaration
Swift
public var richPushHandler: RichPushHandler
-
Device ID that will be used when registering the device to the server along with the device token The default value is
Configuration.shared.userAgentName + "-" + UUID().uuidString
Declaration
Swift
open var deviceId: String { get }
-
Undocumented
Declaration
Swift
public required init(pushHandler: PushHandler, richPushHandler: RichPushHandler)
-
Send the device token to a server API call.
This method is usually called inside the application’s
didRegisterForRemoteNotificationsWithDeviceToken
method to get the device token.The default implementation of this method is checking if a saved device token in the Keychain is the same with the fetched token. If the same, the method does nothing. Otherwise, it calls
DevicesApi.registerDevice
then saves the device token in the Keychain using"DeviceTokenKey"
as keyImportant
Never send the same device token to the server. It can be done by saving the device token somewhere (preferably the Keychain), then checking if the fetched device token is the same with the one that was saved.Declaration
Swift
open func sendDeviceTokenToServerIfNeeded(_ deviceToken: Data)
Parameters
deviceToken
The token of the device as
Data
. -
Register to receive remote notifications via Apple Push Notification service.
The default implementation of this method is calling
UIApplication.shared.registerForRemoteNotifications()
This is usually called after being authorized on
requestAuthorization
completionDeclaration
Swift
open func registerForRemoteNotifications()
-
Requests authorization to interact with the user when local and remote notifications are delivered to the user’s device.
The default implementation of this method is requesting permission to display badge, alerts, and play sounds.
This calls the
requestAuthorization(options:, completionHandler:)
method of theUNUserNotificationCenter
.Declaration
Swift
open func requestAuthorization(options: UNAuthorizationOptions = [.alert, .sound, .badge], completion: @escaping (_ granted: Bool, _ error: Error?) -> Void)
Parameters
options
The authorization options your app is requesting.
completion
The closure to execute asynchronously with the results. It has no return value and has a boolean and an error object as a parameters.
granted
A boolean indicating whether authorization was granted.
error
The error object containing error information or nil if no error occurred.
-
Checks notification’s payload for
message_id
and callsMessagesAPI.trackMessage(id: id, action: .opened)
The default implementation of this method is fetching the value of the notification’s payload
"message_response_id
key, then callsMessagesAPI.trackMessage(id:, action: .opened)
using the fetched valueDeclaration
Swift
open func trackMessage(id: Int)
Parameters
userInfo
The whole notification’s payload
-
Sets the Application’s badge count with the given number if allowed
The default implementation of this method is calling the
UNUserNotificationCenter.current().requestAuthorization(options:, completionHandler:)
, then checks if authorization is granted, then callsUIApplication.shared.applicationIconBadgeNumber = count
in the main queueDeclaration
Swift
open func setApplicationBadgeCount(_ count: Int)
Parameters
count
Number to be displayed on Application’s Icon
-
Handles Push Notification Responses
The default implementation of this method is checking the
response.actionIdentifier
. If it isUNNotificationDismissActionIdentifier
or if theresponse.notification.request.content.userInfo
could not be casted to[String: Any]
, thecompletionHandler
will be executed immediately.Then, if an integer value for the payload’s
message_response_id
field was found, it callstrackMessage
.Then, if a
NotificationType
was not detected, it callspushHandler.handleNotificationWithoutType
.Then, if the
response.actionIdentifier
isUNNotificationDefaultActionIdentifier
, it callspushHandler.handlePush
, otherwise, it callsrichPushHandler.handleRichPushResponse
Declaration
Swift
open func handleNotificationResponse(_ response: UNNotificationResponse, completionHandler: @escaping () -> Void)
Parameters
response
The
UNNotificationResponse
based on the user’s interactioncompletionHandler
Completion block that should always be called