UnbluNotificationApi
class UnbluNotificationApi
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 instance allows us to get the saved x-unblu-device to decline a call. There is no other purpose to have this reference here The instance can be assigned here, but cannot be read from here
Declaration
Swift
var preferencesStorage: (any UnbluPreferencesStorage)? { get set } -
The instance of the UnbluNotificationApi
Declaration
Swift
static let instance: UnbluNotificationApi -
This allows to disable registration for PushKit notifications
Declaration
Swift
static var pushKitEnabled: Bool -
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
UIApplicationDelegateas otherwise notifications may get missed and notifications which got clicked by the user may not be handled. Additionally if noUNUserNotificationCenterDelegateis 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 } -
when there is service notification extension we should not send notification again because it was done by ios
Declaration
Swift
var rescheduleDecryptedNotifications: Bool -
Should be called as soon as the registration for remote notifications via FCM failed
Declaration
Swift
func failedToRegisterForRemoteNotifications(error: any Error)Parameters
errorError cause for failing to register for remote notifications
-
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
UnbluNotificationProcessingErrorif the notification is unable to be processed.Declaration
Swift
func handleLaunchNotification(userInfo: [AnyHashable : Any]?, withCompletionHandler completionHandler: (() -> Void)? = nil) throwsParameters
userInfoThe data dictionary of the notification
-
Can be used to let Unblu handle a notification payload when it is available as a JSON string and does not require a completion handler. Behaves the same as
handleRemoteNotification(userInfo:).Throws
UnbluNotificationProcessingErrorif the notification is unable to be processed by Unblu.Declaration
Swift
func handleRemoteNotification(jsonString: String) throwsParameters
jsonStringJSON string containing the notification payload.
-
Can be used to let Unblu handle a notification payload when it is available as a JSON string and requires a completion handler. Behaves the same as
handleRemoteNotification(userInfo:withCompletionHandler:).Throws
UnbluNotificationProcessingErrorif the notification is unable to be processed by Unblu.Declaration
Swift
func handleRemoteNotification(jsonString: String, withCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) throwsParameters
jsonStringJSON string containing the notification payload.
-
Can be used to let Unblu handle a notification payload that is available as a data dictionary and does not require a completion handler.
Throws
UnbluNotificationProcessingErrorif the notification is unable to be processed by Unblu.Declaration
Swift
func handleRemoteNotification(userInfo: [AnyHashable : Any]) throwsParameters
userInfoThe data dictionary of the notification.
-
Can be used to let Unblu handle a notification payload that is available as a data dictionary and which requires a completion handler.
Throws
UnbluNotificationProcessingErrorif the notification is unable to be processed by Unblu.Declaration
Swift
func handleRemoteNotification(userInfo: [AnyHashable : Any], withCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) throwsParameters
userInfoThe data dictionary of the notification.
-
This function should only be used when implementing your own
UNUserNotificationCenterDelegate.A typical implementation of this in your own
UNUserNotificationCenterDelegatewould be:func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) { do { try UnbluNotificationApi.instance.willPresent(notification: notification, completionHandler: completionHandler) } catch { // your own implementation here } }Throws
UnbluNotificationProcessingErrorif the notification is unable to be processed by Unblu.Declaration
Swift
func willPresent(notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) throwsParameters
notificationThe
UNNotificationobject received fromUNUserNotificationCenterDelegate. -
This function should only be used when implementing your own
UNUserNotificationCenterDelegate.A typical implementation of this in your own
UNUserNotificationCenterDelegatewould be:func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) { do { try UnbluNotificationApi.instance.didReceive(notificationResponse: response, withCompletionHandler: completionHandler) } catch { // your own implementation here } }Throws
UnbluNotificationProcessingErrorif the notification is unable to be processed by Unblu.Declaration
Swift
func didReceive(notificationResponse: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) throwsParameters
notificationResponseThe
UNNotificationResponseobject received fromUNUserNotificationCenterDelegate. -
Receiving a PushKit token
Declaration
Swift
func pushRegistry(token: String) -
Receiving an Incoming call
Declaration
Swift
func pushRegistry(payload: [AnyHashable : Any], completion: @escaping () -> Void) -
When he has finished speaking, start speaking again unless he has been explicitly stopped.
Declaration
Swift
func speechSynthesizer(_ synthesizer: AVSpeechSynthesizer, didFinish utterance: AVSpeechUtterance) -
check if there is a “notificationType” key in the notifications dictionary, which may indicate that it comes from the Unblu collab server
Declaration
Swift
static func isUnbluNotification(userInfo: [AnyHashable : Any]) -> Bool -
Should be used to let Unblu handle an incoming PushKit call notification payload that is available as a data dictionary. This should trigger the appearance of the incoming call UI (CallKit). Forwards the payload to the internal CallKit handling.
Declaration
Swift
func handleIncomingCallPayload(userInfo: [AnyHashable : Any], completion: @escaping () -> Void = {})Parameters
userInfoThe data dictionary of the incoming call payload.
completionCompletion handler called once the payload has been processed.
-
Should be used to let Unblu handle an incoming PushKit call notification payload that is available as a JSON string. This should trigger the appearance of the incoming call UI (CallKit). Internally behaves the same as calling
handleIncomingCallPayload(userInfo:completion:)with the decoded dictionary.Declaration
Swift
func handleIncomingCallPayload(jsonString: String, completion: @escaping () -> Void = {})Parameters
jsonStringJSON string containing the incoming call payload.
completionCompletion handler called once the payload has been processed.