DXNotificationClient
This class is responsible for registering for Push Notifications and making requests to the DX notifications API.
The DXNotificationClient
class simplifies registering your app for Apple Push Notifications and allows you to create and send notifications between users. Notifications can be ephemeral or persisted, in which case you will be able to request those persisted notifications. To use push notifications, you will need to enable it in your app. Take a look at the Enabling the Push Notification Service section from this tutorial for more information.
You will need to enable the "Push Notifications" scope for your app in the developer dashboard before using the notifications API.
Properties
Singleton instance of DXNotificationClient
. You will access all the available DXNotificationClient
methods through this instance.
Methods
register
Register your app for Apple Push Notifications. If you are already using push notifications in your app, you can simply pass in your existing device token.
If you pass in a device token but there is no currently authenticated user, an assertion will be raised.
Parameter
Type
Description
options
[UNAuthorizationOptions]
The authorization options for your notifications.
deviceToken
Data?
If your app is already registered for remote notifications, you can pass in your existing device token.
completion
((Error?) -> Void)?
The closure invoked once the push notification request flow finishes.
error
Error?
An error can occur during the push notification authorization flow, or be returned from the notification API.
didRegisterForRemoteNotifications
Handles device token registration. Your AppDelegate
will need to implement the application(_:didRegisterForRemoteNotificationsWithDeviceToken:)
method, which will then invoke the didRegisterForRemoteNotifications
method, passing in the deviceToken
argument.
Parameter
Type
Description
withDeviceToken
Data
The device token returned by APN.
completion
((Error?) -> Void)?
The closure invoked when the request finishes.
error
Error?
The error returned for an unsuccessful request.
createNotification
Create and send a push notification to another DX user.
Parameter
Type
Description
text
String
The notification text; this is what would be displayed in the notification alert.
receiver
String
The user id of the DX user that will receiver the notification.
persist
Bool
Whether the notification should be persisted; if true, the receiver of the notification will be able to retrieve it when requesting their notifications.
completion
((Error?) -> Void)?
The closure invoked when the request finishes.
error
Error?
The error returned for an unsuccessful request.
readNotifications
Request all persisted notifications for the current user. Supports pagination through the page
and limit
parameters.
Parameter
Type
Description
since
Int?
Return notifications after this date; expected in Unix epoch time. If not provided, will return all notifications.
page
Int?
At what page to return notifications, where page length is determined by limit
.
limit
Int?
The maximum number of notifications to return.
acknowledged
Bool
Whether or not notifications that have been acknowledged should be returned.
completion
(Error?, [DXNotification]?) -> Void
The closure invoked when the request finishes.
error
Error?
The error returned for an unsuccessful request.
notifications
[DXNotification]?
An array of notifications returned for a successful request.
acknowledgeNotification
Acknowledge that a notification has been seen by the current user.
Parameter
Type
Description
notificationId
String
The id of the notification being acknowledged.
completion
((Error?) -> Void)?
The closure invoked when the request finishes.
error
Error?
The error returned for an unsuccessful request.
Last updated