Search code examples
djangoios7xcode5nsurlconnection

NSURLConnection works in Simulator but not from iPad


I have an iOS app that inserts a record into an MySQL server via a Python-Django server, and then immediately queries that information.

I am using [NSURLConnection sendAsynchronousRequest: queue: completionHandler:] with a processing block to parse data from a server JSON object.

The insert statement and query statement are run from separate sendAsynchronousRequests, but the latter is called from the completionHandler block in the former, preventing any race conditions.

On the simulator, this works perfectly and returns the inserted data 100% of the time. On a physical iPad, running iOS7, the response does not ever contain the immediately inserted data.

If I insert a long pause between the two sendAsynchronousRequests using [performSelector: withObject: afterDelay:] it does eventually work -- but I need to add a delay of 2 - 3 seconds.

On the simulator, the timing between the insert and the correct query response is less than 500 ms, so the very long delay should not be necessary and does not seem to be caused by a lower executing process on the simulator.

I have tried Cache-Control: max-age=0, and Expires= headers in my server code, and neither makes a difference, so I don't currently believe that it is a NSURLConnection caching issue.

What else am I overlooking here? Why does this work so perfectly on the Simulator but not on a physical iPad?

Thanks!


Solution

  • I finally figured this out.

    My server code was filtering results based on a calculated time period, which ended "now". The time clock on my iPad was a few seconds into the future compared to the server, while my Mac's clock was in sync with the server. As a result, the records posted from the iPad were getting filtered out.