xcode SwiftSignalRClient错误:试图在连接启动之前发送数据

yws3nbqq  于 2023-03-04  发布在  Swift
关注(0)|答案(1)|浏览(195)

我尝试使用SwiftSignalRClient(https://github.com/moozzyk/SignalR-Client-Swift)获取一些数据。我尝试了以下操作:

private let serverUrl = "https://xxxx"
 private var chatHubConnection: HubConnection
 private weak var chatHubConnectionDelegate: HubConnectionDelegate?
 override func viewDidLoad() {
        super.viewDidLoad()
 self.chatHubConnection?.delegate = ChatHubConnectionDelegate(controller: self)
        chatHubConnection = HubConnectionBuilder(url: URL(string: serverUrl)!).withLogging(minLogLevel: .error)
            .withHttpConnectionOptions(configureHttpOptions: { (httpConnectionOptions) in
                        httpConnectionOptions.headers["Authorization"] = "Bearer \(UserDefaults.standard.accessToken)"
            })
            .build()
        self.chatHubConnection?.start()
        chatHubConnection!.on(method: "ChatStart", callback: { (user: String, message: String) in
                   do {
                      print(user)
                   } catch {
                       print(error)
                   }
               })
               
        chatHubConnection!.start()
        chatHubConnection?.invoke(method: "ChatStart", ["AcceptBid": xxxx], invocationDidComplete: { (error) in
            print(error)
            
        })

在第一个函数中,它甚至不打印用户,也不打印错误,而在第二个函数中,在错误打印时,我得到以下错误:SwiftSignalRClient.SignalRError.invalidOperation(message: "Attempting to send data before connection has been started.

更新:我调用了委托函数connectionDidOpen,我收到以下错误:无可用的支持传输

s6fujrry

s6fujrry1#

我也得到了同样的结果。当我把协议放下并照原样遵循示例时,我得到了一个“任何集线器连接不能是集线器连接”的错误。这是在ChatHubConnection上,没有任何严格的转换或解 Package 修复它。所以我没有放入协议,只是示例化它相同,它运行,但得到相同的结果。我尝试了不同的同步的东西,仍然相同。不知道该怎么办

相关问题