【问题标题】:Swift Twilio Chat iOS 1401 unable to connect to twilio serviceSwift Twilio Chat iOS 1401 无法连接到 twilio 服务
【发布时间】:2017-10-19 08:18:15
【问题描述】:

我成功地将Twilio Chat 集成到Android,现在我正在尝试使用Swift 3 将它集成到iOS

首先要说的:

  • 我按照 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

我也尝试离开频道并在之后重新加入,但仍然无法正常工作。对用户和频道知之甚少却无法执行操作,这很奇怪。

【问题讨论】:

    标签: ios swift3 synchronization twilio channel


    【解决方案1】:

    用户的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")
        }
    }
    

    如果我能进一步帮助您,请告诉我!

    谢谢你,
    兰迪

    【讨论】:

    • 谢谢@rbeiter。我刚刚尝试了您的代码,我处于joined 状态,但我尝试了getMessagesCountgetUsersCount,但都失败了!我仍然不明白为什么我可以知道状态而不知道它的参数或数据
    • 我被困在可编程聊天中,请 Twilio 推荐我
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多