【问题标题】:Twilio iOS SDK fails with "400 Bad request" on outgoing callTwilio iOS SDK 在拨出电话时因“400 Bad request”而失败
【发布时间】:2017-02-25 14:18:42
【问题描述】:

获取here提供的示例源代码,转换为 Swift 3 并应用我生成的升级 Twilio 帐户的令牌。

在尝试拨打电话时,它会播放声音,但在尝试访问https://matrix.twilio.com/2012-02-09/AC ... 时会失败并显示HTTP/1.0 400 Bad request

这是尝试拨打电话后的日志 -

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

可能是什么问题?

【问题讨论】:

标签: ios swift twilio


【解决方案1】:

很难看到代码(带有您输入的参数)来确定真正的问题是什么。但是我会尝试。您的日志文件中有两个问题:

  1. 400 BAD REQUEST 表示:HTTP POSTPUT 中给出的数据验证失败。
  2. longPollConnection : didFailWithError 表示:服务器不可用并且不响应和/或发送新信息。 –––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––

    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}
    

以下是可能的解决方案:

  1. 重置 Xcode 和 iOS 模拟器:How to Reset Xcode and the iOS SimulatorSO post

  2. 如有必要,请更新您的 Podfile:Pod install vs. pod update

  3. 阅读有关可能问题的文章:What is HTTP Long Polling?

  4. 观看这个有用的视频:Advanced Debugging and the Address Sanitizer

  5. 仔细检查这些参数:Voice: Twilio's request

  6. 如果您正在编写自己的客户端,则需要将 HTTP Content-Type 标头设置为 application/x-www-form-urlencoded您的要求。

  7. 您应该检查 response 正文以了解详细信息。

还有其他有用的参考资料:

Sending SMS text message using twilio not working

Twilio: REST API: making calls

¡希望对您有所帮助!

【讨论】:

  • 不,我正在使用他们的官方 SDK,pod TwilioClient。此外,它发生在他们的官方演示项目中。
  • @Kof 你改变了Phone.swift中定义的常量吗?请张贴代码 sn-p。
  • 是的,在Phone.swift 上使用了我的凭据。没什么可展示的,我只是分配了我的 SID 并输入了我的后端 URL。我的 Node.js 后端使用 Twilio Node.js SDK 生成一个有效令牌,然后将其返回到应用程序并用于创建连接。
  • 好的,我等你的消息
【解决方案2】:

在 iOS 10 中,您应该使用 PushKit 来处理传入 VoIP 呼叫的推送通知。因此,当您针对 iOS 10 SDK 构建应用程序时,您需要迁移到 PushKit(可以一直支持到 iOS 8,但是一旦迁移到 iOS 10,我们的建议是将您的最低部署目标更新到 iOS 9)。

【讨论】:

    【解决方案3】:

    我相信您最好的选择是更新到可编程 TwilioVoice SDK 以避免将来出现此类问题,我们开始在使用 TwilioClient 的应用程序中遇到类似问题。 Twilio 已停止支持 TwilioClient SDK。

    请查看:https://www.twilio.com/docs/voice/client/ios

    切换到最新的 SDK 需要从后端/前端进行一些更改,因为它们已弃用 TCDevice、TCConnection 等类。

    如果我能提供帮助,请告诉我。祝你好运。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多