SwiftSwift Native Misc API Reference for Realtime Apps

 
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.

Stops the subscriptions in progress.

pubnub.subscription.disconnect()
This function allow to decrypt the data.
To decrypt the data you can use the following method(s) in Swift SDK.
  1. ParameterTypeRequiredDescription
    dataDataYesThe data to decrypt.
let decryptedString = pubnub.decrypt("data to decrypt")
Initial Data which has been encrypted earlier. nil will be returned in case of decryption error.
This function allow to encrypt the data.
To encrypt the data you can use the following method(s) in Swift SDK.
  1. ParameterTypeRequiredDescription
    messageStringYesThe message to encrypt
let encryptedMessage = pubnub.encrypt("message to encrypt")
Encrypted Base64-encoded string received from Foundation object. nil will be returned in case of failure.
Call the reconnect method to force the SDK to try and reach out PubNub.
To reconnect the data you can use the following method(s) in Swift SDK.
  1. ParameterTypeRequiredDefaultsDescription
    atTimetokenYesThe timetoken to reconnect the subscribe at
    settingHashMapOptionalnilThe Hashmap to reconnect the subscribe with
pubnub.subscription.reconnect()
This function will return a 17 digit precision Unix epoch.
 
Timetoken
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
To fetch Time you can use the following method(s) in Swift SDK
  1. ParameterTypeRequiredDefaultsDescription
    customRequestConfigurationOptionalRequestConfiguration()An object that allows for per-request customization of PubNub Configuration or Network Session
    completion((Result<Timetoken, Error>) -> Void)?OptionalnilThe async Result of the method call

    Completion Handler Result

    • Success: The current Timetoken.
    • Failure: An Error describing the failure.
pubnub.time { result in
  switch result {
  case let .success(timetoken):
    print("Handle downloaded server time token: \(timetoken)")
  case let .failure(error):
    print("Handle response error: \(error.localizedDescription)")
  }
}