Swift Native Misc API Reference for Realtime Apps
Note
The PubNub Swift 3.0 SDK contains many significant changes from the 2.x SDK, including breaking changes. Please refer to the PubNub Swift 3.0 Migration Guide for more details.
The methods on this page are utility methods that don't fit into other categories.
Close PubNub
Description
Stops the subscriptions in progress.
Basic Usage
pubnub.subscription.disconnect()
Decrypt
Description
This function allows to decrypt
the data.
Method(s)
To decrypt
the data you can use the following method(s) in Swift SDK.
decrypt(data: Data)
Parameter Type Required Description data
Data Yes The data
to decrypt.
Basic Usage
let decryptedString = pubnub.decrypt("data to decrypt")
Returns
Initial Data
which has been encrypted earlier. nil
will be returned in case of decryption error.
Encrypt
Description
This function allows to encrypt
the data.
Method(s)
To encrypt
the data you can use the following method(s) in Swift SDK.
encrypt(message: String)
Parameter Type Required Description message
String Yes The message
to encrypt
Basic Usage
let encryptedMessage = pubnub.encrypt("message to encrypt")
Returns
Encrypted Base64-encoded
string received from Foundation object. nil
will be returned in case of failure.
Reconnect
Description
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.
reconnect( at timetoken: Timetoken, setting incomingState: ChannelPresenceState? = nil )
Parameter Type Required Defaults Description at Timetoken Yes The timetoken to reconnect
the subscribe atsetting HashMap Optional nil
The Hashmap to reconnect
the subscribe with
Basic Usage
pubnub.subscription.reconnect()
Time
Description
This function will return a 17 digit precision Unix epoch.
The timetoken is constructed using the following algorithm:
timetoken = (Unix epoch time in seconds) * 10000000
Example of creating a timetoken for a specific time and date
08/19/2013 @ 9:20pm in UTC = 1376961606
timetoken = 1376961606 * 10000000
timetoken = 13769616060000000
Method(s)
To fetch Time
you can use the following method(s) in Swift SDK:
time( custom requestConfig: RequestConfiguration = RequestConfiguration(), completion: ((Result<Timetoken, Error>) -> Void)?)
Parameter Type Required Defaults Description custom
RequestConfiguration Optional RequestConfiguration()
An object that allows for per-request customization of PubNub Configuration or Network Session completion
((Result<Timetoken, Error>) -> Void)? Optional nil
The async Result
of the method callCompletion Handler Result
- Success The current
Timetoken
. - Failure An
Error
describing the failure.
- Success The current
Basic Usage
pubnub.time { result in
switch result {
case let .success(timetoken):
print("Handle downloaded server timetoken: \(timetoken)")
case let .failure(error):
print("Handle response error: \(error.localizedDescription)")
}
}