1
我使用SwiftR來快速整合signalR聊天客戶端。我一步一步將我的obj-c代碼轉換爲swift。作爲迴應,我沒有收到來自callaback方法。它甚至沒有觸及回調點內的破發點在swift中更新聊天客戶端singnalR
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")}
}
我不知道Swift/Objective-C客戶端,但通常情況下,SignalR服務器需要在連接啓動時瞭解集線器。如果我正確讀取此代碼,則首先啓動連接,然後創建一個集線器代理。你有沒有嘗試先創建代理,然後開始連接?這樣客戶端就會知道你不會使用的集線器,並在開始連接時將它作爲connectionData發送到服務器。 – Pawel