iOS:App由于网络连接速度慢而获得SIGKILL?

时间:2012-04-23 20:53:17

标签: ios http networking sigkill

当我在酒店时,他们的Wifi显然是通过非常慢的互联网连接连接到互联网。事实上它可能是调制解调器。

结果是我的应用程序的HTTP GET请求似乎导致iOS向我的应用程序发送了SIGKILL(如Xcode所示)。

为什么呢?怎么解决?

感谢。

1 个答案:

答案 0 :(得分:1)

您需要将HTTP请求放在后台线程中。如果您的主要线程没有响应太长时间,您的应用将被终止。

通常,Web服务的API提供异步提取。你应该使用它。

如果您的API未提供此类...请使用其他API。除此之外,自己把它放在后台。像

这样的东西
- (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);
}