停止&多次启动SignalR-Objc SRHubConnection会使连接不稳定

时间:2015-11-18 11:54:28

标签: ios objective-c signalr signalr.client

在我们使用SignalR-ObjC的iOS应用中,该应用的连接正常。 因为iOS应用程序在后台没有响应,无法接收信号器消息。所以我们有以下实施:

SRHubConnection *connection = [[SRHubConnection alloc] initWithURLString:url useDefault:NO]
  • 应用程序转到后台:[连接停止];停止连接。
  • App来到前景:[连接开始];创建一个新的连接对象并启动它。

但是如果我们连续3到4次在背景和前景之间切换,会使连接不稳定并且不再连接并抛出跟随错误。

[HTTP_BASED_TRANSPORT]
Cleandisconnectfailed.ErrorDomain=NSURLErrorDomainCode=-1001"The request timed out."UserInfo={
  NSUnderlyingError=0x159283ae0{
    ErrorDomain=kCFErrorDomainCFNetworkCode=-1001"The request timed out."UserInfo={
      NSErrorFailingURLStringKey=http: //websiteurl.net/signalr/abort?clientProtocol=1.3.0.0&connectionData=%5B%7B%22Name%22%3A%22hotlinechathub%22%7D%5D&connectionToken=wxhidka/adfaf/MDf57llaaBz22i55k7%2BUVNX4DHCixM1hX1k%2BhVy/Yi1FwnwMdwhzIrgpaeD5E4oC%2B702UnosdkQL1z2FrgebWw2uY0qCh9LG0Zfj9ZdY2pRG0&transport=longPolling,
      NSErrorFailingURLKey=http: //website.net/signalr/abort?clientProtocol=1.3.0.0&connectionData=%5B%7B%22Name%22%3A%22hotlinechathub%22%7D%5D&connectionToken=gcukXaFIN/wm4ilNrj/MDf57llaaBz22i55k7%2BUVNX4DHCixM1hX1k%2BhVy/Yi1FwnwMdwhzIrgpaeD5E4oC%2B702UnosdkQL1z2FrgebWw2uY0qCh9LG0Zfj9ZdY2pRG0&transport=longPolling,
      _kCFStreamErrorCodeKey=-2102,
      _kCFStreamErrorDomainKey=4,
      NSLocalizedDescription=Therequesttimedout.
    }
  },
  NSErrorFailingURLStringKey=http: //website.net/signalr/abort?clientProtocol=1.3.0.0&connectionData=%5B%7B%22Name%22%3A%22hotlinechathub%22%7D%5D&connectionToken=gcukXaFIN/wm4ilNrj/MDf57llaaBz22i55k7%2BUVNX4DHCixM1hX1k%2BhVy/Yi1FwnwMdwhzIrgpaeD5E4oC%2B702UnosdkQL1z2FrgebWw2uY0qCh9LG0Zfj9ZdY2pRG0&transport=longPolling,
  NSErrorFailingURLKey=http: //website.net/signalr/abort?clientProtocol=1.3.0.0&connectionData=%5B%7B%22Name%22%3A%22hotlinechathub%22%7D%5D&connectionToken=gcukXaFIN/wm4ilNrj/MDf57llaaBz22i55k7%2BUVNX4DHCixM1hX1k%2BhVy/Yi1FwnwMdwhzIrgpaeD5E4oC%2B702UnosdkQL1z2FrgebWw2uY0qCh9LG0Zfj9ZdY2pRG0&transport=longPolling,
  _kCFStreamErrorDomainKey=4,
  _kCFStreamErrorCodeKey=-2102,
  NSLocalizedDescription=Therequesttimedout.
}

错误:

[CONNECTION]
negotiationfailedErrorDomain=NSURLErrorDomainCode=-1001 
"The request timed out."UserInfo={Same as displayed above}

问题: 有没有办法阻止SRHubConnection进入这种不稳定状态并启动新连接而没有错误?

1 个答案:

答案 0 :(得分:0)

确保您没有在连接对象上多次调用startstop。 多次调用它们会导致连接处于不稳定状态。