title: Swift Twilio Chat iOS 1401 unable to connect to twilio service
body: <p>I successfully integrate <code>Twilio Cha</code>t to <code>Android</code> and now I'm trying to integrate it to <code>iOS</code> using <code>Swift 3</code>.</p>
  
  <p>First things to say:</p>
  
  <ul>
  <li>I followed instructions as frameworks in <code>Embedded libraires</code> and <code>libstdc++</code> to Linked Libs and run scripts to build phases</li>
  <li>I got a generated and usable token from a server and a SID from an existing channel where identity susbscribed</li>
  <li>The only difference with Android is that my <code>TwilioChatClientProperties</code>is just an init one.</li>
  </ul>
  
  <p>So here is my problem: I generate a ChatClient instance using my token, the client connects and I can retrieve SIDs of subscribed channels but when I want to join the one with the SID received that's not succeed and I got the following error</p>
  
  <pre><code>error code 1401: Unable to establish connection to Twilio Sync service
  </code></pre>
  
  <p>I checked the client connects but doesn't synchronize</p>
  
  <p>here is my code:</p>
  
  <pre><code>let props = TwilioChatClientProperties.init()
  
  TwilioChatClient.chatClient(withToken: token, properties: props, delegate: self ){
          (result, client) -&gt; Void in
                if (result?.isSuccessful())!{ //=&gt; 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")
                                }
                            })
                        }
                    }
                  }
   }
  </code></pre>
  
  <p>I don't know why can I retrieve channels but not join one of them!</p>
  
  <p>After few more effort I'm still at the same level. I would like to add some informations about my logs, here are the last logs when I try to synchronize:</p>
  
  <pre><code>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 &gt;&gt; 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
  </code></pre>
  
  <p>I tried also to leave a channel and to rejoin after, still not working. This is strange to know few things about user and channels but not be able to do actions.</p>