Reputation:
When I was at a hotel, their Wifi apparently was connected to the Internet via a very very slow Internet connection. It may have been modem based in fact.
The result was that my app's HTTP GET request appears to have caused iOS to send my app a SIGKILL (as Xcode indicates).
Why? How to fix?
Thanks.
Upvotes: 0
Views: 592
Reputation: 28409
You need to put your HTTP request in a background thread. If your main thread is unresponsive for too long, your app will be terminated.
Normally, the API for web services provide an asynchronous fetch. You should be using that.
If your API does not provide such... use a different API. Barring that, put it in the background yourself. Something like
- (void)issuePotentiallyLongRequest
{
dispatch_queue_t q = dispatch_queue_create("my background q", 0);
dispatch_async(q, ^{
// The call to dispatch_async returns immediately to the calling thread.
// The code in this block right here will run in a different thread.
// Do whatever stuff you need to do that takes a long time...
// Issue your http get request or whatever.
[self.httpClient goFetchStuffFromTheInternet];
// Now, that code has run, and is done. You need to do something with the
// results, probably on the main thread
dispatch_async(dispatch_get_main_queue(), ^{
// Do whatever you want with the result. This block is
// now running in the main thread - you have access to all
// the UI elements...
// Do whatever you want with the results of the fetch.
[self.myView showTheCoolStuffIDownloadedFromTheInternet];
});
});
dispatch_release(q);
}
Upvotes: 1