UnbluNotificationApiProtocol

public protocol UnbluNotificationApiProtocol : AnyObject

Interface to use notifications with unblu. As Firebase Cloud Messaging (FCM) SDK is build as a static library, we can not include it here. Most functions of this api should be called for specific notification callbacks typically fired in the AppDelegate.

Unblu will display/handle notifications as shown in the following table. Api helper to check mainly if notifications are from unblu or not

Unblu will display/handle notifications as shown in the following table.

| App state | New Message | Incoming Call |


| background | show notification | show notification |


| foreground unblu UI closed | show notification | Trigger UnbluUiEventApi.UiVisibilityRequest |


| foreground unblu UI open | Does nothing | Does nothing |


Whenever a notification is clicked, the event UnbluUiEventApi.UiVisibilityRequest is triggered.

  • The current device push notification token. This should be set every time the application receives a new token from the system in order to notify the Unblu server.

    Declaration

    Swift

    var deviceToken: String? { get set }
  • Enables/disables the automatic handling of notfications.

    When enabled, it should be called at the very beginning when the application gets launched inside the UIApplicationDelegate as otherwise notifications may get missed and notifications which got clicked by the user may not be handled. Additionally if no UNUserNotificationCenterDelegate is set it will set its own delegate to it.

    When disabled, the API of this class can and should still be used to handle notifications from Unblu which got into the application by a custom implementation and/or for local notifications

    Declaration

    Swift

    var automaticHandlingEnabled: Bool { get set }
  • Should be called on start of the application if with the userInfo stored inside “launchOptions?[.remoteNotification] as? [AnyHashable: Any]”. Can be nil if no notification was clicked to open the application.

    Throws

    UnbluNotificationProcessingError if the notification is unable to be processed.

    Declaration

    Swift

    func handleLaunchNotification(userInfo: [AnyHashable : Any]?, withCompletionHandler completionHandler: (() -> Void)?) throws

    Parameters

    userInfo

    The data dictionary of the notification

    completionHandler

    An optional completion handler that is called if the notifcation can be processed by Unblu.

  • Should be called on each notification the application receives and which does not require to call a completionHandler. It will throw an error if the notification is not an unblu notification and must not be processed by the host application.

    Throws

    UnbluNotificationProcessingError if the notification is unable to be processed by Unblu.

    Declaration

    Swift

    func handleRemoteNotification(userInfo: [AnyHashable : Any]) throws

    Parameters

    userInfo

    The data dictionary of the notification

  • Should be called on each notification the application receives and which requires to call a completionHandler. It will either call the completionHandler directly if it is an Unblu notification or it will throw an error if the notification is not an Unblu notification and must not be processed by the host application.

    Throws

    UnbluNotificationProcessingError if the notification is unable to be processed by Unblu.

    Declaration

    Swift

    func handleRemoteNotification(userInfo: [AnyHashable : Any], withCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) throws

    Parameters

    userInfo

    The data dictionary of the notification

    completionHandler

    Called when the notification is handled directly by Unblu

  • Should be called as soon as the registration for remote notifications via FCM failed

    Declaration

    Swift

    func failedToRegisterForRemoteNotifications(error: Error)

    Parameters

    error

    Error cause for failing to register for remote notifications