Created
August 6, 2018 14:46
-
-
Save funkyboy/1dff33c55ed4b8d84e63a04d42ba8971 to your computer and use it in GitHub Desktop.
Test recover
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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