MPNDevice

public class MPNDevice : CustomStringConvertible

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 LightstreamerClient in order to successfully subscribe an MPN subscription. See MPNSubscription.

After creation, an MPNDevice object is in “unknown” state. It must then be passed to the Lightstreamer Server with the LightstreamerClient.register(forMPN:) 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 LightstreamerClient.MPNSubscriptions collection.

An MPNDevice’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” at the first subsequent registration.

  • The status of the device.

    See more

    Declaration

    Swift

    public enum Status : String
  • 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 MPNDevice 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.

    Precondition

    the application ID may be obtained from the main bundle.

    Declaration

    Swift

    public init(deviceToken: String)

    Parameters

    deviceToken

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

  • Adds a delegate that will receive events from the MPNDevice instance.

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

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

    Declaration

    Swift

    public func addDelegate(_ delegate: MPNDeviceDelegate)

    Parameters

    delegate

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

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

    Lifecycle: a delegate can be removed at any time.

    See also

    addDelegate(_:)

    Declaration

    Swift

    public func removeDelegate(_ delegate: MPNDeviceDelegate)

    Parameters

    delegate

    The delegate to be removed.

  • List containing the MPNDeviceDelegate instances that were added to this MPNDevice.

    See also

    addDelegate(_:)

    Declaration

    Swift

    public var delegates: [MPNDeviceDelegate] { get }
  • 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.

    Declaration

    Swift

    public let platform: String
  • 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.

    Declaration

    Swift

    public let applicationId: String
  • The device token 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.

    Declaration

    Swift

    public let deviceToken: String
  • The previous device token 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.

    Declaration

    Swift

    public let previousDeviceToken: String?
  • Checks whether the MPNDevice is currently registered on the server or not.

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

    Lifecycle: this property can be read at any time.

    See also

    status

    Declaration

    Swift

    public var isRegistered: Bool { get }
  • Checks whether the MPNDevice 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 true by server sent suspension events, and back to false in case of client disconnection or server sent resume events.

    Lifecycle: this property can be read at any time.

    See also

    status

    Declaration

    Swift

    public var isSuspended: Bool { get }
  • 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.

    See also

    isRegistered

    See also

    isSuspended

    Declaration

    Swift

    public var status: Status { get }
  • The server-side timestamp of the device status.

    Lifecycle: this property can be read at any time.

    See also

    status

    Declaration

    Swift

    public var statusTimestamp: Int64? { get }
  • 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 subscriptions from the previous token to the new one and the device ID remains unaltered.

    Lifecycle: this property can be read at any time.

    Declaration

    Swift

    public var deviceId: String? { get }
  • Declaration

    Swift

    public var description: String { get }