Push Notifications - Device Activation and Subscription

This object is accessible through client.push and provides to push-compatible devices :

activate(callback: (ARTErrorInfo, DeviceDetails?) → Void)

Register the device for push. When the activation process is completed, Ably will call the didActivateAblyPush(error: ARTErrorInfo?) method from the ARTPushRegistererDelegate.

deactivate(deregisterCallback: (ARTErrorInfo, deviceId: String?) → Void)

Deregister the device for push. When the deactivation process is completed, Ably will call the didDeactivateAblyPush(error: ARTErrorInfo?) method from theARTPushRegistererDelegate.

A DeviceDetails is a type encapsulating attributes of a device registered for push notifications.

Properties

id
unique identifier for the device generated by the device itselfType: String
clientId
optional trusted client identifier for the deviceType: String
formFactor
form factor of the push device. Must be one of phone, tablet, desktop, tv, watch, car or embeddedType: String
metadata
optional metadata object for this device. The metadata for a device may only be set by clients with push-admin privilegesType: Object
platform
platform of the push device. Must be one of ios or androidType: String
deviceSecret
Secret value for the device.Type: String
push.recipient
push recipient details for this device. See the REST API push publish documentation for more detailsType: Object
push.state
the current state of the push device being either Active, Failing or FailedType: String
push.errorReason
when the device’s state is failing or failed, this attribute contains the reason for the most recent failureType: ErrorInfo

An extension of DeviceDetails. In addition to the properties of DeviceDetails, it includes the following:

Properties

deviceIdentityToken
a unique identity token for the deviceType: String

A PushChannel is a property of a RealtimeChannel or RestChannel. It provides push devices the ability to subscribe and unsubscribe to push notifications on channels.

Methods

subscribeDevice()

Subscribe your device to the channel’s push notifications.

subscribeClient()

Subscribe all devices associated with your device’s clientId to the channel’s push notifications.

unsubscribeDevice()

Unsubscribe your device from the channel’s push notifications.

unsubscribeClient()

Unsubscribe all devices associated with your device’s clientId from the channel’s push notifications.

listSubscriptions(deviceId: String?, clientId: String?, deviceClientId: String?, `channel: String?, callback: (ARTPaginatedResult<PushChannelSubscription>?, ARTErrorInfo?) → Void)

Lists push subscriptions on a channel specified by its channel name (channel). These subscriptions can be either be a list of client (clientId) subscriptions, device (deviceId) subscriptions, or if concatFilters is set to true, a list of both. This method requires clients to have the Push Admin capability. For more information, see GET rest.ably.io/push/channelSubscriptions Rest API.

Parameters

callback
called with a ARTPaginatedResult<PushChannelSubscription> object or an error

Callback result

On success, resultPage contains a PaginatedResult encapsulating an array of PushChannelSubscription objects corresponding to the current page of results. PaginatedResult supports pagination using next() and first() methods.

On failure to retrieve message history, err contains an ErrorInfo object with the failure reason.

An PushChannelSubscription is a type encapsulating the subscription of a device or group of devices sharing a client identifier to a channel in order to receive push notifications.

Properties

channel
the channel that this push notification subscription is associated withType: String
deviceId
the device with this identifier is linked to this channel subscription. When present, clientId is never presentType: String
clientId
devices with this client identifier are included in this channel subscription. When present, deviceId is never presentType: String

PushChannelSubscription.forDevice(String channel, String deviceId) → PushChannelSubscription

A static factory method to create a PushChannelSubscription object for a channel and single device.

Parameters

channel
channel name linked to this push channel subscriptionType: String
deviceId
the device with this identifier will be linked with this push channel subscriptionType: String

Returns

A PushChannelSubscription object

PushChannelSubscription.forClient(String channel, String clientId) → PushChannelSubscription

A static factory method to create a PushChannelSubscription object for a channel and group of devices sharing a client identifier.

Parameters

channel
channel name linked to this push channel subscriptionType: String
clientId
devices with this client identifier are included in the new push channel subscriptionType: String

Returns

A PushChannelSubscription object

A PaginatedResult is a type that represents a page of results for all message and presence history, stats and REST presence requests. The response from a Ably REST API paginated query is accompanied by metadata that indicates the relative queries available to the PaginatedResult object.

Properties

Methods

first(callback: (ARTPaginatedResult?, ARTErrorInfo?) → Void)

Returns a new PaginatedResult for the first page of results.

Boolean hasNext()

Returns true if there are more pages available by calling next and returns false if this page is the last page available.

Boolean isLast()

Returns true if this page is the last page and returns false if there are more pages available by calling next available.

next(callback: (ARTPaginatedResult?, ARTErrorInfo?) → Void)

Returns a new PaginatedResult loaded with the next page of results. If there are no further pages, then nil is returned.

Swift v1.2
channel.history { paginatedResult, error in let paginatedResult = paginatedResult! print("Page 0 item 0: \((paginatedResult.items[0] as! ARTMessage).data)") paginatedResult.next { nextPage, error in let nextPage = nextPage! print("Page 1 item 1: \((nextPage.items[1] as! ARTMessage).data)") print("Last page? \(nextPage.isLast())") } }
Copied!
Select...