NSURLConnection sendSynchronousRequest - 前景背景 [英] NSURLConnection sendSynchronousRequest - background to foreground

查看:198
本文介绍了NSURLConnection sendSynchronousRequest - 前景背景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用sendSynchronousRequest从服务器获取数据。我知道同步会等到收到该请求的数据。

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

但是当用户错误地输入一些不存在的url而不是尝试获得响应时,问题就出现了。在这种情况下,如果用户进入后台并进入前台,则仅显示黑屏。它只显示状态栏。它也没有显示任何背景应用。我必须按Home键才能退出我的应用程序。

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.

在模拟器上,1分钟后它会显示请求超时的消息(没有崩溃) 。

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

在设备上,1分钟内应用程序崩溃。

On Device, within 1 min application get crashes.

任何建议。任何帮助。这在我的应用程序中确实是一个严重的问题。

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

谢谢。

推荐答案

<就像朱利安说的那样,看门狗正在杀死你的应用程序。回答一些问题:

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


  • 为什么这只发生在模拟器上?
    因为当您调试看门狗时,单独留下您的应用程序,可能需要一些时间。

  • 为什么只有当用户输入错误的网址时才会发生这种情况?
    由于系统超时,如果找不到服务器,系统将继续尝试60秒。

  • 所以问题是同步还是异步?
    不,问题是线程,你可以在后台线程中执行相同的操作,只是不要在主线程上执行它,看门狗会让你独自一人。

  • 当应用程序出现时为什么屏幕变黑?
    请记住,你正在主线程上创建阻塞内容,这个线程会吸引......

  • 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.

这篇关于NSURLConnection sendSynchronousRequest - 前景背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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