Swift Twilio Chat iOS 1401无法连接到twilio服务

时间:2017-05-19 09:14:09

标签: ios swift3 synchronization twilio channel

我已成功将Twilio Cha t集成到Android,现在我尝试使用iOS将其集成到Swift 3

首先要说的是:

  • 我按照Embedded libraireslibstdc++中的框架将指令作为链接库并运行脚本来构建阶段
  • 我从服务器获得了一个生成且可用的令牌,并从现有的通道中获取了一个SID
  • 与Android的唯一区别是我的TwilioChatClientProperties只是初始版。

所以这是我的问题:我使用我的令牌生成一个ChatClient实例,客户端连接,我可以检索订阅频道的SID但是当我想加入收到SID的那个时,我没有成功,我得到以下错误

error code 1401: Unable to establish connection to Twilio Sync service

我检查了客户端连接,但没有同步

这是我的代码:

let props = TwilioChatClientProperties.init()

TwilioChatClient.chatClient(withToken: token, properties: props, delegate: self ){
        (result, client) -> Void in
              if (result?.isSuccessful())!{ //=> success
                 for channel in (client?.channelsList().subscribedChannels())!{
                     if channel.sid == channel_sid{ 
                         // found
                         channel.join(completion: { (resultJoinChannel) in 
                          // never print anything
                              if(resultJoinChannel?.isSuccessful())!{
                                    print("joined channel")
                              }else{
                                    print("pb joining channel")
                              }
                          })
                      }
                  }
                }
 }

我不知道为什么我可以检索频道但不加入其中一个频道!

经过几次努力,我仍处于同一水平。我想添加一些关于我的日志的信息,这是我尝试同步时的最后日志:

2017-05-26 10:52:09.090925+0200 [967:593374] SyncDocument[1]:
    0x1aec7cb40 | 05/26/10:52:09.090 | CRITICAL | 38     
   | SyncDocument | request 5 flowId xxx 
    error code 1401: Unable to establish connection to Twilio Sync service
2017-05-26 10:52:09.091380+0200 [967:593374] TNRawHttp[2]:
    0x1aec7cb40 | 05/26/10:52:09.091 | WARNING  | 13     
   | TNRawHttp | Could not find any requests for this id: xxx
2017-05-26 10:52:09.091609+0200 [967:593374] SyncDocument[1]:
    0x1aec7cb40 | 05/26/10:52:09.091 | CRITICAL | 40     
   | SyncDocument | request 6 flowId xxx 
    error code 1401: Unable to establish connection to Twilio Sync service
2017-05-26 10:52:09.091887+0200 [967:593374] TNRawHttp[2]:
    0x1aec7cb40 | 05/26/10:52:09.091 | WARNING  | 13     
| TNRawHttp | Could not find any requests for this id: xxx
2017-05-26 10:52:09.092098+0200 [967:593374] SyncDocument[1]:
    0x1aec7cb40 | 05/26/10:52:09.092 | CRITICAL | 42     
   | SyncDocument | request 7 flowId xxx 
    error code 1401: Unable to establish connection to Twilio Sync service
2017-05-26 10:52:09.092704+0200 [967:593374] TNRawHttp[2]:
    0x1aec7cb40 | 05/26/10:52:09.092 | WARNING  | 13     
   | TNRawHttp | Could not find any requests for this id: xxx
2017-05-26 10:52:09.093595+0200 [967:593374] SyncDocument[1]:
    0x1aec7cb40 | 05/26/10:52:09.093 | CRITICAL | 44     
   | SyncDocument | request 8 flowId xxx 
    error code 1401: Unable to establish connection to Twilio Sync service
2017-05-26 10:52:09.093876+0200 [967:593374] TNRawHttp[2]: 
   0x1aec7cb40 | 05/26/10:52:09.093 | WARNING  | 13     
   | TNRawHttp | Could not find any requests for this id: xxx
2017-05-26 10:52:09.094077+0200 [967:593374] SyncDocument[1]: 
   0x1aec7cb40 | 05/26/10:52:09.093 | CRITICAL | 46     
   | SyncDocument | request 9 flowId xxx 
    error code 1401: Unable to establish connection to Twilio Sync service
2017-05-26 10:52:09.094368+0200 [967:593374] TNRawHttp[2]: 
   0x1aec7cb40 | 05/26/10:52:09.094 | WARNING  | 13     
   | TNRawHttp | Could not find any requests for this id: xxx
2017-05-26 10:52:09.106080+0200 [967:593765] TNHttpTwilsockMessageResult[2]:        
0x16e5f3000 | 05/26/10:52:09.105 | WARNING  | TNHttpTwilsockMessageResult 
   | Could not deliver http request via twilsock: Twilsock has been stopped
2017-05-26 10:52:09.106325+0200 [967:593765] IPM[1]:
    0x16e5f3000 | 05/26/10:52:09.106 | CRITICAL 
    | IPM | public channel request request failed for CHxxxx
2017-05-26 10:52:09.106867+0200 [967:593765] TNRegNotificationCtxSession[2]:
    0x16e5f3000 | 05/26/10:52:09.106 | WARNING  | 19     | TNRegNotificationCtxSession 
    | Could not operate with notification context in twilsock. Error 9
2017-05-26 10:52:09.109605+0200 [967:593766] TNWebsocket[1]:
    0x16e67f000 | 05/26/10:52:09.109 | CRITICAL | 4      
    | TNWebsocket 
    | Received error while waiting for message: Exception: Bad socket descriptor
2017-05-26 10:52:09.110852+0200 [967:593765] TNFinalState[2]:
    0x16e5f3000 | 05/26/10:52:09.110 | WARNING  | 49     
    | TNFinalState | Unexpected event: Error
   0x1aec7cb40 | 05/26/10:52:09.111 | INFO
    | 35     | SyncMap | destructed
   0x1aec7cb40 | 05/26/10:52:09.111 | INFO
    | 29     | SyncList | destructed
   0x16e5f3000 | 05/26/10:52:09.111 | INFO
    | 1      | TNTwilsockClient | onDisconnectedImpl >> Final state
   0x16e5f3000 | 05/26/10:52:09.112 | WARNING
    | 49     | TNFinalState | Unexpected event: Disconnected
   0x16e5f3000 | 05/26/10:52:09.112 | DEBUG
    | 1      | TNTwilsockClient | ~TNTwilsockClient - begin
   0x16e5f3000 | 05/26/10:52:09.113 | DEBUG
    | 1      | TNTwilsockClient | Cleaning observers list - begin
   0x16e5f3000 | 05/26/10:52:09.113 | DEBUG
    | 1      | TNTwilsockClient | Cleaning observers list - end
   0x16e5f3000 | 05/26/10:52:09.114 | DEBUG
    | 1      | TNTwilsockClient | ~TNTwilsockClient - end
   0x16e2ab000 | 05/26/10:52:09.616 | DEBUG
    | 22     | TSSubscriptions | Sending subscription request for action: establish
   0x16e2ab000 | 05/26/10:52:09.616 | INFO
    | 12     | TNHttpTransportClient | trying to send request to: https://cds.us1.twilio.com/v4/Subscriptions
   0x16e2ab000 | 05/26/10:52:09.616 | CRITICAL
    | 12     | TNHttpTransportClient | Http transport has been shut down
   0x16e2ab000 | 05/26/10:52:09.616 | WARNING
    | 22     | TSSubscriptions | Error while persisting subscriptions: establish
   0x16e2ab000 | 05/26/10:52:14.055 | DEBUG
    | 22     | TSSubscriptions | Sending subscription request for action: establish
   0x16e2ab000 | 05/26/10:52:14.055 | INFO
    | 12     | TNHttpTransportClient | trying to send request to: https://cds.us1.twilio.com/v4/Subscriptions
   0x16e2ab000 | 05/26/10:52:14.055 | CRITICAL
    | 12     | TNHttpTransportClient | Http transport has been shut down
   0x16e2ab000 | 05/26/10:52:14.056 | WARNING
    | 22     | TSSubscriptions | Error while persisting subscriptions: establish
   0x16df63000 | 05/26/10:52:20.937 | DEBUG
    | 22     | TSSubscriptions | Sending subscription request for action: establish
   0x16df63000 | 05/26/10:52:20.937 | INFO
    | 12     | TNHttpTransportClient | trying to send request to: https://cds.us1.twilio.com/v4/Subscriptions
   0x16df63000 | 05/26/10:52:20.937 | CRITICAL
    | 12     | TNHttpTransportClient | Http transport has been shut down
   0x16df63000 | 05/26/10:52:20.937 | WARNING
    | 22     | TSSubscriptions | Error while persisting subscriptions: establish
   0x16df63000 | 05/26/10:52:35.238 | DEBUG
    | 22     | TSSubscriptions | Sending subscription request for action: establish
   0x16df63000 | 05/26/10:52:35.238 | INFO
    | 12     | TNHttpTransportClient | trying to send request to: https://cds.us1.twilio.com/v4/Subscriptions
   0x16df63000 | 05/26/10:52:35.239 | CRITICAL
    | 12     | TNHttpTransportClient | Http transport has been shut down
   0x16df63000 | 05/26/10:52:35.239 | WARNING
    | 22     | TSSubscriptions | Error while persisting subscriptions: establish
   0x16df63000 | 05/26/10:52:51.354 | DEBUG
    | 22     | TSSubscriptions | Sending subscription request for action: establish
   0x16df63000 | 05/26/10:52:51.354 | INFO
    | 12     | TNHttpTransportClient | trying to send request to: https://cds.us1.twilio.com/v4/Subscriptions
   0x16df63000 | 05/26/10:52:51.354 | CRITICAL
    | 12     | TNHttpTransportClient | Http transport has been shut down
   0x16df63000 | 05/26/10:52:51.354 | WARNING
    | 22     | TSSubscriptions | Error while persisting subscriptions: establish
   0x16df63000 | 05/26/10:53:25.597 | DEBUG
    | 22     | TSSubscriptions | Sending subscription request for action: establish
   0x16df63000 | 05/26/10:53:25.598 | INFO
    | 12     | TNHttpTransportClient | trying to send request to: https://cds.us1.twilio.com/v4/Subscriptions
   0x16df63000 | 05/26/10:53:25.598 | CRITICAL
    | 12     | TNHttpTransportClient | Http transport has been shut down
   0x16df63000 | 05/26/10:53:25.598 | WARNING
    | 22     | TSSubscriptions | Error while persisting subscriptions: establish
   0x16df63000 | 05/26/10:54:08.247 | DEBUG
    | 22     | TSSubscriptions | Sending subscription request for action: establish
   0x16df63000 | 05/26/10:54:08.248 | INFO
    | 12     | TNHttpTransportClient | trying to send request to: https://cds.us1.twilio.com/v4/Subscriptions
   0x16df63000 | 05/26/10:54:08.248 | CRITICAL
    | 12     | TNHttpTransportClient | Http transport has been shut down
   0x16df63000 | 05/26/10:54:08.248 | WARNING
    | 22     | TSSubscriptions | Error while persisting subscriptions: establish

我还试图留下一个频道,然后重新加入,仍然没有工作。知道关于用户和频道的一些事情但却无法采取行动,这很奇怪。

1 个答案:

答案 0 :(得分:0)

用户的subscribedChannels数组只包含他们已经成为其成员的频道。是否有可能在您的Android客户端上,身份已经是所需频道的成员,但在iOS客户端上它是不同的身份?此外,只需在首次加入频道时调用join,从那时起,一旦客户端初始化,该频道将可供用户使用。

如果您已经知道channel_sid,找到所需频道的最佳方法是使用channel(withSidOrUniqueName sidOrUniqueName, completion)方法。请注意,这不会找到尚未邀请或添加身份的private个频道。

我建议您尝试以下代替for循环:

chatClient?.channelsList().channel(withSidOrUniqueName: channel_sid) {
    (result, channel) -> Void in
    if (result?.isSuccessful())! {
        if (channel?.status == .joined) {
            print("already joined channel")
        } else {
            channel?.join(completion: { (resultJoinChannel) in
                if (resultJoinChannel?.isSuccessful())! {
                    print("joined channel")
                } else {
                    print("problem joining channel")
                }
            })
        }
    }  else {
        print("problem finding channel")
    }
}

如果我能进一步为您提供帮助,请与我们联系!

谢谢你,
好色