2016-10-16 55 views
12

將提供的示例源代碼here轉換爲Swift 3並應用我生成的升級Twilio帳戶的令牌。Twilio iOS SDK在傳出呼叫時出現「400 Bad request」失敗

當試圖撥打電話時,它播放聲音,但在嘗試訪問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:[email protected];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 

什麼可以是問題?

+0

您是否能夠讀取響應中發送的錯誤消息(除了400錯誤代碼)?像這樣顯示在這裏:https://www.twilio.com/docs/api/errors#debugging-calls-to-the-rest-api – aksh1t

+0

我沒有檢查實際的請求/響應,但不是日誌中寫的是什麼? – Kof

+0

向我們顯示您的代碼 – Sulthan

回答

0

很難看不到一個代碼(帶有你輸入的參數)來確定真正的問題是什麼。但是我會努力的。有你的日誌文件中的兩個問題:

  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和iPhone模擬器: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. 如果你正在編寫你自己的客戶端,你需要設置HT TP內容類型頭到application/x-www-form-urlencoded爲您的請求。

  7. 您應該檢查一個response正文的細節。

還有其他有用的參考資料:

Sending SMS text message using twilio not working

Twilio: REST API: making calls

¡希望這有助於!

+0

不,我正在使用他們的官方SDK,pod'TwilioClient'。此外,它發生在他們的官方演示項目上。 – Kof

+0

@Kof您是否更改過Phone.swift中定義的常量?請發佈代碼片段。 – andy

+0

是的,在'Phone.swift'上使用我的憑證。沒有什麼可展示的,我只是分配了我的SID並放置了我的後端網址。我的Node.js後端使用Twilio Node.js SDK生成一個有效的標記,然後將其返回到應用程序並用於創建連接。 – Kof

0

在iOS 10中,您應該使用PushKit來處理傳入VoIP呼叫的推送通知。因此,當您針對iOS 10 SDK構建應用程序時,需要轉移到PushKit(可以一直支持到iOS 8,但是一旦移動到iOS 10,我們的建議是將最低部署目標更新爲iOS 9)。