.NET CORE 2.1.403 SignalR对Swift的官方支持

时间:2018-12-06 15:26:54

标签: swift asp.net-core .net-core signalr

我已经在 .NET CORE 2.1.403 上开发了一个WebApi后端项目,所有的webapi路由都运行良好。现在,我需要对使用Swift开发的iOS应用程序进行实时更新。

我找不到任何支持SignalR的官方库。搜索后,我发现支持.NET CORE的{​​{3}},但是没有可依靠的详细文档。但是,我的Javascript客户端与 .NET CORE 一起使用时效果很好。

我以前将https://github.com/moozzyk/SignalR-Client-Swift.NET FRAMEWORK 4.7.1 SignalR一起使用过,并且工作正常。

根据SwiftR的建议,Swift客户端上没有任何计划。在这方面的任何建议都会有所帮助。

1 个答案:

答案 0 :(得分:3)

我意识到这是一个迟来的答复,但就其价值而言,我已经成功地将iOS中的https://github.com/moozzyk/SignalR-Client-Swift SignalR客户端用于AspNet Core服务器实现。 GitHub上的文档很少,但是使用起来非常简单。例如:

// Set up a connection to the SignalR hub on the servver.
private func connectToSignalRHub() {
    // Are we already connected to the hub?
    if !isHubConnected {
        let url = URL(string: "http://\(hostName):\(serverPort)/hub")!
        hubConnection = HubConnectionBuilder(url: url).withLogging(minLogLevel: .error).build()
        if let hub = hubConnection {
            hub.delegate = self

            // Set our callbacks for the messages we expect from the SignalR hub.
            hub.on(method: "ProgressUpdate", callback: {
                args, typeConverter in
                if let data = try? typeConverter.convertFromWireType(obj: args[0], targetType: String.self) {
                    self.onHubProgressUpdate(progress: data)
                }
            })

            // Start the hub connection.
            hub.start()
        }
    }
}

如果您仍然需要,我很乐意分享更多细节。