PushManager
open class PushManager:
PushManagerProtocol
Object representing the PushManager used to manage subscriptions
The PushManager
object is the main interface provided by this crate
it allow consumers to manage push subscriptions. It exposes methods that
interact with the autopush server
and persists state representing subscriptions.
-
Declaration
Swift
required public init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer)
-
Creates a new [
PushManager
] object, not subscribed to any channels# Arguments
config
: The PushConfiguration for the PushManager
# Errors Returns an error in the following cases:
- PushManager is unable to open the
database_path
given
Declaration
Swift
public convenience init(config: PushConfiguration) throws
-
Decrypts a raw push message.
This accepts the content of a Push Message (from websocket or via Native Push systems). # Arguments:
payload
: The Push payload as received by the client from Push.
# Returns Decrypted message body
# Errors Returns an error in the following cases:
- The PushManager does not contain a valid UAID
- There are no records associated with the UAID the [
PushManager
] contains - An error occurred while decrypting the message
- An error occurred accessing the PushManager’s persisted storage
Declaration
Swift
open func decrypt(payload: [String : String]) throws -> DecryptResponse
-
Retrieves an existing push subscription
# Arguments
scope
- Site scope string
# Returns A Subscription response that includes the following:
- A URL that can be used to deliver push messages
- A cryptographic key that can be used to encrypt messages
that would then be decrypted using the [
PushManager::decrypt
] function
# Errors Returns an error in the following cases:
- PushManager was unable to access its persisted storage
- An error occurred generating or deserializing the cryptographic keys
Declaration
Swift
open func getSubscription(scope: String) throws -> SubscriptionResponse?
-
Subscribes to a new channel and gets the Subscription Info block
# Arguments
scope
- Site scope stringserver_key
- optional VAPID public key to “lock” subscriptions (defaults to “” for no key)
# Returns A Subscription response that includes the following:
- A URL that can be used to deliver push messages
- A cryptographic key that can be used to encrypt messages
that would then be decrypted using the [
PushManager::decrypt
] function
# Errors Returns an error in the following cases:
- PushManager was unable to access its persisted storage
- An error occurred sending a subscription request to the autopush server
- An error occurred generating or deserializing the cryptographic keys
Declaration
Swift
open func subscribe(scope: String, appServerSey: String? = nil) throws -> SubscriptionResponse
-
Unsubscribe from given scope, ending that subscription for the user.
# Arguments
scope
- The scope for the channel to remove
# Returns Returns a boolean. Boolean is False if the subscription was already terminated in the past.
# Errors Returns an error in the following cases:
- An error occurred sending an unsubscribe request to the autopush server
- An error occurred accessing the PushManager’s persisted storage
Declaration
Swift
open func unsubscribe(scope: String) throws -> Bool
-
Unsubscribe all channels for the user
# Errors Returns an error in the following cases:
- The PushManager does not contain a valid UAID
- An error occurred sending an unsubscribe request to the autopush server
- An error occurred accessing the PushManager’s persisted storage
Declaration
Swift
open func unsubscribeAll() throws
-
Updates the Native OS push registration ID.
# Arguments:
new_token
- the new Native OS push registration ID
# Errors Return an error in the following cases:
- The PushManager does not contain a valid UAID
- An error occurred sending an update request to the autopush server
- An error occurred accessing the PushManager’s persisted storage
Declaration
Swift
open func update(registrationToken: String) throws
-
Verifies the connection state
NOTE: This does not resubscribe to any channels it only returns the list of channels that the client should re-subscribe to.
# Returns Returns a list of [
PushSubscriptionChanged
] indicating the channels the consumer the client should re-subscribe to. If the list is empty, the client’s connection was verified successfully, and the client does not need to resubscribe# Errors Return an error in the following cases:
- The PushManager does not contain a valid UAID
- An error occurred sending an channel list retrieval request to the autopush server
- An error occurred accessing the PushManager’s persisted storage
Declaration
Swift
open func verifyConnection(forceVerify: Bool = false) throws -> [PushSubscriptionChanged]