Utility Methods API for Swift Native SDK
The methods on this page are utility methods that don't fit into other categories.
Encrypt
This function allows to encrypt
the data.
Availability
For more information, refer to Crypto module configuration.
Method(s)
To encrypt
the data you can use the following method(s) in Swift SDK.
func encrypt(data: Data)
Parameter | Description |
---|---|
data *Type: Data | The message to encrypt. |
Basic Usage
Encrypt part of message
Reference code
This example is a self-contained code snippet ready to be run. It includes necessary imports and executes methods with console logging. Use it as a reference when working with other examples in this document.
Returns
Success
Encrypted Data
received from the Foundation object.
Failure
An Error
describing the failure.
Decrypt
This function allows to decrypt
the data.
Availability
For more information, refer to Crypto module configuration.
Method(s)
To decrypt
the data you can use the following method(s) in Swift SDK.
func decrypt(data: Data) -> Result<Data, Error>
Parameter | Description |
---|---|
data *Type: Data | The data to decrypt. |
Basic Usage
Decrypt part of message
Returns
Success
Initial Data
which has been encrypted earlier.
Failure
An Error
describing the failure.
Disconnect
Call the disconnect
method to stops the subscriptions in progress.
Methods
To disconnect
the data you can use the following methods in Swift SDK.
func disconnect( )
Basic Usage
Reconnect
Call the reconnect
method to force the SDK to try and reach out PubNub.
Method(s)
To reconnect
the data you can use the following method(s) in Swift SDK.
func reconnect(at timetoken: Timetoken? = nil)
Parameter | Description |
---|---|
at * Type: Timetoken Default: n/a | The timetoken to reconnect the subscribe at. |
Basic Usage
Time
This function will return a 17 digit precision Unix epoch.
Algorithm constructing the timetoken
timetoken = (Unix epoch time in seconds) * 1_000_000_000
Example of creating a timetoken for a specific time and date:
// 08/19/2013 @ 9:20pm in UTC = 1376961606
timetoken = 1376961606 * 1_000_000_000
timetoken = 1376961606000000000
Method(s)
To fetch Time
you can use the following method(s) in Swift SDK:
func time(
custom requestConfig: PubNub.RequestConfiguration = PubNub.RequestConfiguration(),
completion: ((Result<Timetoken, Error>) -> Void)?
)
Parameter | Description |
---|---|
custom Type: PubNub.RequestConfiguration Default: PubNub.RequestConfiguration() | An object that allows for per-request customization of PubNub Configuration or Network Session. |
completion Type: ((Result<Timetoken, Error>) -> Void)? Default: nil | The async Result of the method call. |
Completion Handler Result
Success
The current Timetoken
.
Failure
An Error
describing the failure.
Basic Usage
Get PubNub Timetoken