Our thinking

iPhone app not getting server response on AT&T only

21 September 2012

I spent the last 24 hours trying to figure out why an iPhone app would not get answers from its cakephp backend server on AT&T only (3G and 4G). The app would work properly on the same device over Wifi. We tested other devices running on Sprint and Verizon, they were able to receive data from the server.

We were able to monitor the query leaving the iPhone app, getting to the server, and the server sending the correct answer. The content length would be the same for each call but the iPhone would get different data:

Over wifi

Over AT&T

Notice here that the answer gotten over AT&T is shorter than the one over Wifi. It is then impossible for the json parser to interpret just a portion of the data explaining why the “Data to String” (stringification of the NSDictionary previously printed as “Data”) is null.

Here is how we fixed the problem: by manually setting the content-type of the answer in the header of the response:

// ————————————————————–
header(‘Content-type: application/json’);
// ————————————————————–

My guess is that AT&T would not transfer all of the HTTP response at once and the iPhone would close the connection too early. Setting the content type would tell AT&T that all the data block has to be transferred at once.