在swift中更新聊天客户端singnalR

时间:2016-11-28 07:09:35

标签: ios swift signalr swiftr

我正在使用SwiftR在swift中集成signalR聊天客户端。我将我的obj-c代码逐步转换为swift。我没有从callaback方法得到任何反应。它甚至没有达到回调中的断点

           SwiftR.connect("https://chat.f.com") { connection in
        connection.headers=["Authorization":bearerKey]

        self.chatHub = connection.createHubProxy("MobileChatHub")

        self.chatHub?.on("ChatContactsResponse", callback: { (response) in
            print("ChatContactsResponse")
            print(response as AnyObject)
        })
        self.chatHub?.on("GetChatsResponse", callback: { (response) in
            print("GetChatsResponse")
            print(response as AnyObject)
        })
        self.chatHub?.on("GetChatsResponse", callback: { (response) in
            print("GetChatsResponse")
            print(response as AnyObject)
        })

        connection.starting = { print("started")}
        connection.connected = { print("connected: \(connection.connectionID)") }
        connection.connectionSlow = { print("connectionSlow") }
        connection.reconnecting = { print("reconnecting") }
        connection.reconnected = { print("reconnected") }
        connection.disconnected = { print("disconnected")}
    }

1 个答案:

答案 0 :(得分:1)

你做得对。

但你已经忘了connection.start() 如果您正在查看#127 line here演示,请找到Expected Output