18

Took the source code of example provided here, converted to Swift 3 and applied my generated token of an upgraded Twilio account.

When trying to make a call, it plays a sound, but then fails with a HTTP/1.0 400 Bad request when trying to access https://matrix.twilio.com/2012-02-09/AC ....

Here's the log after trying to make a call -

2016-10-16 18:32:12.955056 MyApp[577:121739] [DEBUG TCDeviceInternal] Inside TCDeviceInternal initWithCapabilityToken, capabilityToken_: (null)
2016-10-16 18:32:12.961112 MyApp[577:121739] [VERBOSE TCDeviceInternal] Inside decodeCapabilityToken:, Header: {
    alg = HS256;
    typ = JWT;
}
2016-10-16 18:32:12.962305 MyApp[577:121739] [VERBOSE TCDeviceInternal] Inside decodeCapabilityToken:, payload: {
    exp = 1476635532;
    iss = ....REMOVED....................;
    scope = "scope:client:incoming?clientName=TestName scope:client:outgoing?appSid=AP.....REMOVED......&clientName=TestName";
}
2016-10-16 18:32:12.962611 MyApp[577:121739] [VERBOSE TCDeviceInternal] Scope URI: scope:client:incoming?clientName=TestName, inside setCapabilitiesWithCapabilityToken:
2016-10-16 18:32:12.962860 MyApp[577:121739] [VERBOSE TCDeviceInternal] Scope URI: scope:client:outgoing?appSid=AP.............REMOVED.......&clientName=TestName, inside setCapabilitiesWithCapabilityToken:
2016-10-16 18:32:12.963710 MyApp[577:121739] [DEBUG TCConstants] X-Twilio-Client string: {"p":"ios","v":"1.2.7.b99-1015b1f","mobile":{"arch":"unknown type 16777228 subtype 1","product":"iPhone","name":"iPhone8,4","v":"10.0.2"}}, inside TCConstants clientString
2016-10-16 18:32:13.035381 MyApp[577:121739] [VERBOSE Twilio] Inside initWithConfig:, codec: speex/16000/1 -> priority: 255
2016-10-16 18:32:13.035425 MyApp[577:121739] [VERBOSE Twilio] Inside initWithConfig:, codec: speex/8000/1 -> priority: 254
2016-10-16 18:32:13.035457 MyApp[577:121739] [VERBOSE Twilio] Inside initWithConfig:, codec: speex/32000/1 -> priority: 0
2016-10-16 18:32:13.035500 MyApp[577:121739] [VERBOSE Twilio] Inside initWithConfig:, codec: opus/48000/1 -> priority: 0
2016-10-16 18:32:13.035574 MyApp[577:121739] [VERBOSE Twilio] Inside initWithConfig:, codec: PCMU/8000/1 -> priority: 128
2016-10-16 18:32:13.035669 MyApp[577:121739] [VERBOSE Twilio] Inside initWithConfig:, codec: PCMA/8000/1 -> priority: 0
2016-10-16 18:32:13.035843 MyApp[577:121739] [DEBUG Twilio] Inside startStateNotificationsForObject, delegate: <TCDeviceInternal: 0x17018c710>
2016-10-16 18:32:13.036069 MyApp[577:121739] [VERBOSE Twilio] Inside addUserAccount:, Registration URL: sip:TestName@chunderm.gll.twilio.com;transport=tls
2016-10-16 18:32:13.037112 MyApp[577:121739] [DEBUG TwilioReachability] Reachability Flag Status: -R ------- networkStatusForFlags
2016-10-16 18:32:13.037191 MyApp[577:121739] [DEBUG TCDeviceInternal] Internet reachability: 1
2016-10-16 18:32:13.037434 MyApp[577:121739] [DEBUG TCDeviceInternal] Created TCDeviceInternal: <TCDeviceInternal: 0x17018c710> for accountId: 0
2016-10-16 18:32:13.038306 MyApp[577:121739] [DEBUG TCHttpJsonLongPollConnection] Inside TCHTTPJSONLongPollConnection run(), gonna connect to host matrix.twilio.com, port 443
2016-10-16 18:32:13.039266 MyApp[577:121739] [DEBUG TCHttpJsonLongPollConnection] Inside onSocketWillConnect, sock: <TCAsyncSocket 0x17418ddd0 local nowhere remote nowhere has queued 0 reads 0 writes, no current read, no current write, read stream 0x17010d260 not open, write stream 0x1701065d0 not open, not connected>, self: <TCHttpJsonLongPollConnection 0x1740aa9e0 url=https://matrix.twilio.com/2012-02-09/.........REMOVED............../TestName?AccessToken=...............REMOVED......................&feature=publishPresence&feature=presenceEvents connected=0 https=1>
2016-10-16 18:32:13.052355 MyApp[577:121739] [DEBUG TCSoundManager] TCSoundManager: sharedInstance: 0x0
2016-10-16 18:32:13.052423 MyApp[577:121739] [DEBUG TCSoundManager] TCSoundManager init, top
2016-10-16 18:32:13.052461 MyApp[577:121739] [VERBOSE TCSoundManager] TCSoundManager init, starting
2016-10-16 18:32:13.109491 MyApp[577:121739] [DEBUG TCSoundManager] TCSoundManager: player configured
2016-10-16 18:32:13.120029 MyApp[577:121739] [VERBOSE TCSoundManager] TCSoundManager init, done
2016-10-16 18:32:13.120917 MyApp[577:121739] [DEBUG TCSoundManager] TCSoundManager: attempting to play item, (inside TCSoundManager play())
2016-10-16 18:32:13.121720 MyApp[577:121739] [DEBUG TCSoundManager] Player status: 0, inside observeValueForKeyPath:
[2016-10-16 18:32:13.123] Caller.swift:55 DEBUG: Twilio connection created successfully
2016-10-16 18:32:13.136004 MyApp[577:121739] [DEBUG TCSoundManager] Player status: 1, inside observeValueForKeyPath:
2016-10-16 18:32:13.145341 MyApp[577:121739] [DEBUG TCSoundManager] Item status: 1, inside observeValueForKeyPath:
2016-10-16 18:32:13.226409 MyApp[577:121739] [DEBUG TCHttpJsonLongPollConnection] Inside beginning of onSocket:didConnectToHost
2016-10-16 18:32:13.226632 MyApp[577:121739] [DEBUG TCHttpJsonLongPollConnection] Starting TLS with settings:
{
    kCFStreamSSLPeerName = "*.twilio.com";
    kCFStreamSSLValidatesCertificateChain = 1;
    kCFStreamSocketSecurityLevelNegotiatedSSL = kCFStreamPropertySocketSecurityLevel;
}, inside onSocket:didConnectToHost:
2016-10-16 18:32:13.227088 MyApp[577:121739] [DEBUG TCEventStream] Inside longPollConnectionDidConnect:, stream <TCEventStream: 0x17427cbc0> connected
2016-10-16 18:32:13.227331 MyApp[577:121739] [DEBUG TCHttpJsonLongPollConnection] REQUEST: URL: https://matrix.twilio.com/2012-02-09/.............REMOVED............/TestName?AccessToken=..........................................REMOVED..................................&feature=publishPresence&feature=presenceEvents   GET /2012-02-09/........REMOVED............/ProjectName App?AccessToken=................................REMOVED....................................&feature=publishPresence&feature=pres
2016-10-16 18:32:14.028697 MyApp[577:121739] [DEBUG TCHttpJsonLongPollConnection] Inside beginning of onSocket:didReadData
2016-10-16 18:32:14.028836 MyApp[577:121739] [VERBOSE TCHttpJsonLongPollConnection] Received 
HTTP/1.0 400 Bad request
Cache-Control: no-cache
Connection: close
Content-Type: text/html

, inside onSocket:didReadData
2016-10-16 18:32:14.029065 MyApp[577:121739] [DEBUG TCEventStream] Inside longPollConnection:didReceiveHeaders:, stream <TCEventStream: 0x17427cbc0> got headers
2016-10-16 18:32:14.030074 MyApp[577:121739] [DEBUG TCEventStream] Inside longPollConnection:didFailWithError:, stream <TCEventStream: 0x17427cbc0> disconnected, error Error Domain=com.twilio.client.TCHttpErrorDomain Code=4 "HTTP server returned non-success status" UserInfo={com.twilio.client.TCHttpStatusCodeKey=400, NSLocalizedDescription=HTTP server returned non-success status}
2016-10-16 18:32:15.017604 MyApp[577:121739] [INFO TCSoundManager] TCSoundManager: playerItemDidReachEnd: 7466A900, (inside playerItemDidReachEnd)
2016-10-16 18:32:15.017913 MyApp[577:121739] [DEBUG TCCommandHandler] Inside postCommand:, received command of type TCMakeCallCommand
2016-10-16 18:32:15.018535 MyApp[577:121739] [DEBUG TCSoundManager] Player status: 1, inside observeValueForKeyPath:
2016-10-16 18:32:21.396771 MyApp[577:121739] [DEBUG Twilio] Application is in background
2016-10-16 18:32:21.397023 MyApp[577:121739] Legacy VoIP background mode is deprecated and no longer supported

What can be the issue?

Andy Jazz
  • 49,178
  • 17
  • 136
  • 220
Kof
  • 23,893
  • 9
  • 56
  • 81
  • Are you able to read the error message being sent in the response (apart from the 400 error code)? Something like that's shown here: https://www.twilio.com/docs/api/errors#debugging-calls-to-the-rest-api – aksh1t Oct 18 '16 at 18:48
  • I didn't inspect the actual request/response, but isn't that what's written in the log? – Kof Oct 19 '16 at 08:05
  • Show us your code – Sulthan Oct 22 '16 at 07:30
  • As mentioned above - https://github.com/devinrader/SwiftPhone – Kof Oct 25 '16 at 06:20
  • Same issue here, TCMakeCallCommand seems to be failing with EXC_BAD_ACCESS. Let me know if you figure this one out. – Guven Nov 02 '16 at 01:30

3 Answers3

1

It's quite difficult not seeing a code (with parameters you entered) to determine what the real problem is. But I will try. There are two issues in your log file:

  1. 400 BAD REQUEST means: the data given in the HTTP POST or PUT failed validation.
  2. longPollConnection : didFailWithError means: the server is not available and doesn't respond and/or send the new information. ––––––––––––––––––––––––––––––––––––––––––––

    2016-10-16 18:32:14.030074 MyApp[577:121739] [DEBUG TCEventStream] Inside longPollConnection:didFailWithError:, stream <TCEventStream: 0x17427cbc0> disconnected, error Error Domain=com.twilio.client.TCHttpErrorDomain Code=4 "HTTP server returned non-success status" UserInfo={com.twilio.client.TCHttpStatusCodeKey=400, NSLocalizedDescription=HTTP server returned non-success status}
    

Here are possible solutions for you:

  1. Reset Xcode and iOS Simulator: How to Reset Xcode and the iOS Simulator and SO post

  2. Update your Podfile if it's necessary: Pod install vs. pod update

  3. Read the article about possible problem: What is HTTP Long Polling?

  4. Watch this useful video: Advanced Debugging and the Address Sanitizer

  5. Double-check these parameters: Voice: Twilio's request

  6. If you are writing your own client, you need to set the HTTP Content-Type header to application/x-www-form-urlencoded for your requests.

  7. You should inspect a response body for details.

And there are other useful references:

Sending SMS text message using twilio not working

Twilio: REST API: making calls

¡Hope this helps!

Community
  • 1
  • 1
Andy Jazz
  • 49,178
  • 17
  • 136
  • 220
  • Nope, I'm using their official SDK, pod `TwilioClient`. Further more, it happens on their official demo project. – Kof Oct 19 '16 at 04:17
  • @Kof Have you changed the constants defined in Phone.swift? Please, post a code snippet. – Andy Jazz Oct 19 '16 at 06:35
  • Yes, used my credentials on `Phone.swift`. There's not much to show, I just assigned my SID and put my backend URL. My Node.js backend generates a valid token using Twilio Node.js SDK, which is then returned to the app and used to create a connection. – Kof Oct 19 '16 at 07:57
  • Ok, I'll be waiting for news from you – Andy Jazz Oct 25 '16 at 06:24
0

In iOS 10, you should be using PushKit for handling push notifications for incoming VoIP calls. So when you build your app against the iOS 10 SDK, you need to move over to PushKit (which can be supported all the way back to iOS 8, but once you move to iOS 10 our recommendation is to update your minimum deployment target to iOS 9).

Danieboy
  • 4,393
  • 6
  • 32
  • 57
0

I believe your best bet is to update to Programmable TwilioVoice SDK to avoid such issues in future, we started to face the similar issues in our applications using TwilioClient. Twilio has discontinued support for the TwilioClient SDK.

Please review this: https://www.twilio.com/docs/voice/client/ios

Switching to the latest SDK requires some changes from both back/front ends as they have deprecated classes like TCDevice, TCConnection etc.

Do let me know if i could be of some help. Good luck.