SwiftSwift Native Misc API Reference for Realtime Apps

 
These docs are for the new PubNub Swift SDK written purely in Swift. To view the docs for the older version (the PubNub Objective-C SDK wrapper for Swift), have a look here.

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 & 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
pubnub.time { result in
  switch result {
  case let .success(response):
    print("Handle downloaded server time token using: \(response.timetoken)")
  case let .failure(error):
    print("Handle response error: \(error.localizedDescription)")
  }
}
Response objects which is returned by client when Time API is used:
//Example of status
{
  error: false,
  operation: 'PNTimeOperation',
  statusCode: 200
}

//Example of response
{
  timetoken: 15031768233407550
}