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 |
| The authorization options for your notifications. |
deviceToken |
| If your app is already registered for remote notifications, you can pass in your existing device token. |
completion |
| The closure invoked once the push notification request flow finishes. |
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 |
| The device token returned by APN. |
completion |
| The closure invoked when the request finishes. |
error |
| The error returned for an unsuccessful request. |
createNotification
Create and send a push notification to another DX user.
Parameter | Type | Description |
text |
| The notification text; this is what would be displayed in the notification alert. |
receiver |
| The user id of the DX user that will receiver the notification. |
persist |
| Whether the notification should be persisted; if true, the receiver of the notification will be able to retrieve it when requesting their notifications. |
completion |
| The closure invoked when the request finishes. |
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 |
| Return notifications after this date; expected in Unix epoch time. If not provided, will return all notifications. |
page |
| At what page to return notifications, where page length is determined by |
limit |
| The maximum number of notifications to return. |
acknowledged |
| Whether or not notifications that have been acknowledged should be returned. |
completion |
| The closure invoked when the request finishes. |
error |
| The error returned for an unsuccessful request. |
notifications |
| 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 |
| The id of the notification being acknowledged. |
completion |
| The closure invoked when the request finishes. |
error |
| The error returned for an unsuccessful request. |
Last updated