Skip to content

Instantly share code, notes, and snippets.

@funkyboy
Created August 6, 2018 14:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save funkyboy/1dff33c55ed4b8d84e63a04d42ba8971 to your computer and use it in GitHub Desktop.
Save funkyboy/1dff33c55ed4b8d84e63a04d42ba8971 to your computer and use it in GitHub Desktop.
Test recover
import UIKit
import Ably
class ViewController: UIViewController {
var serial:Int64 = 0;
var recover:String = "";
let options = ARTClientOptions()
override func viewDidLoad() {
super.viewDidLoad()
options.key = "KEY"
let firstClient = ARTRealtime(options: options)
let firstChannel = firstClient.channels.get("test")
firstChannel.on(.attached) { _ in
firstChannel.publish(nil, data: "message", callback: { errorInfo in
if (errorInfo == nil) {
self.serial = firstClient.connection.serial
self.recover = firstClient.connection.recoveryKey!
print("serial is \(self.serial)")
self.useSecondClient()
}
})
}
firstChannel.attach()
}
func useSecondClient() {
options.recover = self.recover
let secondClient = ARTRealtime(options: options)
let secondChannel = secondClient.channels.get("test")
secondChannel.on(.attached) { _ in
secondChannel.subscribe{ _ in
print("secondClient.connection.serial \(secondClient.connection.serial)")
}
secondChannel.publish(nil, data: "message2", callback: { errorInfo in
if (errorInfo == nil) {
print("Second message published")
}
})
}
secondChannel.attach()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment