iOS:由于网络连接速度缓慢,应用程序收到SIGKILL? [英] iOS: App gets SIGKILL due to slow network connection?

查看:198
本文介绍了iOS:由于网络连接速度缓慢,应用程序收到SIGKILL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

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

The result was that my app's HTTP GET request appears to have caused iOS to send my app a SIGKILL (as Xcode indicates).

为什么?如何解决?

谢谢。

推荐答案

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

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.

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

Normally, the API for web services provide an asynchronous fetch. You should be using that.

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

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);
}

这篇关于iOS:由于网络连接速度缓慢,应用程序收到SIGKILL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆