Search code examples
iphoneiosios4nsurlconnection

NSURLConnection sendSynchronousRequest - background to foreground


I m using sendSynchronousRequest to get the data from the server. I know that synchronous will wait until the data received for that request.

But the problem comes when user by mistake enters some non-existing url and than tries to get response. In this case, if user goes in to background and than comes into foreground it shows only black screen. It only shows status bar. Also its not showing any background application. I have to press Home button to come out of my application.

On simulator, After 1+ minute it shows me the message that "Request time out" (No crash).

On Device, within 1 min application get crashes.

Any suggestion. Any Help. This is really a serious issue in my app.

Thanks.


Solution

  • Just like Julien said, the watchdog is killing your app. To answer some questions:

    • why does this happen only on the simulator? Because when you're debugging the watchdog leaves your app alone, it can take time.
    • why does this happen only when the user enters a wrong url? Because of the system timeout, the system will keep trying for 60 secs if it can't find a server.
    • so the problem is synchronous vs asynchronous? No, the problem is the thread, you can do the same operation in a background thread, just don't do it on the main thread and the watchdog will leave you alone.
    • why is the screen black when the app comes up? Remember, you are making blocking stuff on the main thread, the thread that draws...

    Hope that was all. Let me know if I missed something.