LSMPNDevice Class Reference

Inherits from NSObject
Declared in LSMPNDevice.h

Overview

Class representing a device that supports Mobile Push Notifications (MPN).

It contains device details and the delegate needed to monitor its status.

An MPN device is created from a device token obtained from system’s Remote User Notification APIs, and must be registered on the LSLightstreamerClient in order to successfully subscribe an MPN subscription. See .

After creation, an LSMPNDevice object is in “unknown” state. It must then be passed to the Lightstreamer Server with the [LSLightstreamerClient registerForMPN:] method, which enables the client to subscribe MPN subscriptions and sends the device details to the server’s MPN Module, where it is assigned a permanent deviceId and its state is switched to “registered”.

Upon registration on the server, active MPN subscriptions of the device are received and exposed in the [LSLightstreamerClient MPNSubscriptions] collection.

An LSMPNDevice’s state may become “suspended” if errors occur during push notification delivery. In this case MPN subscriptions stop sending notifications and the device state is reset to “registered” only when a new device token is provided.

– initWithDeviceToken:

Creates an object to be used to describe an MPN device that is going to be registered to the MPN Module of Lightstreamer Server.

During initialization the LSMPNDevice tries to acquires some more details:

  • The application ID, through the app’s Main Bundle.

  • Any previously registered device token, from the User Defaults storage.

It then saves the current device token on the User Defaults storage. Saving and retrieving the previous device token is used to handle automatically the cases where the token changes, such as when the app state is restored from a device backup. The MPN Module of Lightstreamer Server is able to move MPN subscriptions associated with the previous token to the new one.

- (nonnull instancetype)initWithDeviceToken:(nonnull NSString *)deviceToken

Parameters

deviceToken

The device token obtained through the system’s Remote User Notification APIs. Must be represented with a contiguous string of hexadecimal characters.

Exceptions

NSException

If the application ID can’t be obtained from the main bundle.

Declared In

LSMPNDevice.h

– addDelegate:

Adds a delegate that will receive events from the LSMPNDevice instance.

The same delegate can be added to several different LSMPNDevice instances.

Lifecycle: a delegate can be added at any time. A call to add a delegate already present will be ignored.

- (void)addDelegate:(nonnull id<LSMPNDeviceDelegate>)delegate

Parameters

delegate

An object that will receive the events as documented in the LSMPNDeviceDelegate interface. Note: delegates are stored with weak references: make sure you keep a strong reference to your delegates or they may be released prematurely.

Declared In

LSMPNDevice.h

– removeDelegate:

Removes a delegate from the LSMPNDevice instance so that it will not receive events anymore.

Lifecycle: a delegate can be removed at any time.

- (void)removeDelegate:(nonnull id<LSMPNDeviceDelegate>)delegate

Parameters

delegate

The delegate to be removed.

See Also

Declared In

LSMPNDevice.h

  delegates

List containing the LSMPNDeviceDelegate instances that were added to this LSMPNDevice.

@property (nonatomic, readonly, nonnull) NSArray<id<LSMPNDeviceDelegate> > *delegates

See Also

Declared In

LSMPNDevice.h

  platform

The platform identifier of this MPN device. It equals to the constant Apple and is used by the server as part of the device identification.

Lifecycle: this property can be read at any time.

@property (nonatomic, readonly, nonnull) NSString *platform

Declared In

LSMPNDevice.h

  applicationId

The application ID of this MPN device. It is determined automatically from the main bundle identifier and is used by the server as part of the device identification.

Lifecycle: this property can be read at any time.

@property (nonatomic, readonly, nonnull) NSString *applicationId

Declared In

LSMPNDevice.h

  deviceToken

The device token ID of this MPN device. It is passed during creation and is used by the server as part of the device identification.

Lifecycle: this property can be read at any time.

@property (nonatomic, readonly, nonnull) NSString *deviceToken

Declared In

LSMPNDevice.h

  previousDeviceToken

The previous device token ID of this MPN device. It is obtained automatically from the User Defaults storage during creation and is used by the server to restore MPN subscriptions associated with this previous token. May be nil if no MPN device has been registered yet on the application.

Lifecycle: this property can be read at any time.

@property (nonatomic, readonly, nullable) NSString *previousDeviceToken

Declared In

LSMPNDevice.h

  registered

Checks whether the LSMPNDevice is currently registered on the server or not.

This flag is switched to YES by server sent registration events, and back to NO in case of client disconnection or server sent suspension events.

Lifecycle: this property can be read at any time.

@property (nonatomic, readonly, getter=isRegistered) BOOL registered

See Also

Declared In

LSMPNDevice.h

  suspended

Checks whether the LSMPNDevice is currently suspended on the server or not.

An MPN device may be suspended if errors occur during push notification delivery.

This flag is switched to YES by server sent suspension events, and back to NO in case of client disconnection or server sent resume events.

Lifecycle: this property can be read at any time.

@property (nonatomic, readonly, getter=isSuspended) BOOL suspended

See Also

Declared In

LSMPNDevice.h

  status

The status of the device.

The status can be:

  • UNKNOWN: when the MPN device has just been created or deleted.

  • REGISTERED: when the MPN device has been successfully registered on the server.

  • SUSPENDED: when a server error occurred while sending push notifications to this MPN device and consequently it has been suspended.

Lifecycle: this property can be read at any time.

@property (nonatomic, readonly, nonnull) NSString *status

Declared In

LSMPNDevice.h

  statusTimestamp

The server-side timestamp of the device status.

Lifecycle: this property can be read at any time.

@property (nonatomic, readonly, nullable) NSDate *statusTimestamp

See Also

Declared In

LSMPNDevice.h

  deviceId

The server-side unique persistent ID of the device.

The ID is available only after the MPN device has been successfully registered on the server. I.e. when its status is REGISTERED or SUSPENDED.

Note: a device token change, if the previous device token was correctly stored on the User Defaults storage, does not cause the device ID to change: the server moves previous MPN subscription from the previous token to the new one and the device ID remains unaltered.

Lifecycle: this property can be read at any time.

@property (nonatomic, readonly, nullable) NSString *deviceId

Declared In

LSMPNDevice.h