DXNotificationClient

This class is responsible for registering for Push Notifications and making requests to the DX notifications API.

public class DXNotificationClient

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

public static let shared: DXNotificationClient

Singleton instance of DXNotificationClient. You will access all the available DXNotificationClient methods through this instance.

Methods

register

public func register(
    options: [UNAuthorizationOptions] = [.badge, .sound, .alert], 
    deviceToken: Data? = nil, 
    _ completion: ((_ error: Error?) -> Void)?
) -> Void

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.

didRegisterForRemoteNotifications

public func didRegisterForRemoteNotifications(
    withDeviceToken deviceToken: Data, 
    _ completion: ((_ error: Error?) -> Void)?
) -> Void

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.

createNotification

public func createNotification(
    text: String, 
    receiver: String, 
    persist: Bool = true, 
    _ completion: ((_ error: Error?) -> Void)?
) -> Void

Create and send a push notification to another DX user.

readNotifications

public func readNotifications(
    since: Int? = nil, 
    page: Int? = nil, 
    limit: Int? = nil, 
    acknowledged: Bool = true, 
    _ completion: @escaping (_ error: Error?, _ notifications: [DXNotification]?) -> Void
) -> Void

Request all persisted notifications for the current user. Supports pagination through the page and limit parameters.

acknowledgeNotification

public func acknowledgeNotification(
    notificationId: String, 
    _ completion: ((_ error: Error?) -> Void)?
) -> Void

Acknowledge that a notification has been seen by the current user.

Last updated