[英]How to pause execution of app until the response of a web service comes in iPhone
I am working on an iPhone app in which I am calling a web service in my app for accomplishing the same I am creating a NSURLConnection the parsing of data is based upon the response of connection delegate's didReceiveResponse: method. 我正在开发一个iPhone应用程序,在其中我要在应用程序中调用Web服务以完成相同的工作。我正在创建NSURLConnection,数据的解析基于连接委托的didReceiveResponse:方法的响应。 I would like to halt the execution of my code until I get any response from my service but I am not sure how to do the same.
我想在我的服务收到任何响应之前停止执行代码,但是我不确定该怎么做。 Please let me know if you have solution.
如果您有解决方案,请告诉我。
Thanks Sandy 谢谢桑迪
In my opinion what you want to do is not halt the execution of your code (Apple won't be happy about it) but rather alert the user that you're waiting for something and disable your UI for anything you don't want the user to do in the meantime. 在我看来,您要做的不是停止执行代码(Apple对此不会感到满意),而是提醒用户您正在等待某些内容,并为您不需要的任何内容禁用UI。用户在此期间要做的事情。
You can construct a fairly standard and simple way for this, which go something like this: 您可以为此构建一个相当标准和简单的方法,如下所示:
When you get the didReceiveResponse remove the "wait" view and go about with dealing with the response you got. 当您获得didReceiveResponse时,请删除“等待”视图,然后继续处理您得到的响应。
Sorry, I don't have the code right in front of me, but there is a blocking NSUrlRequest. 抱歉,我前面没有代码,但是有一个阻塞的NSUrlRequest。 Search for blocking/NSURL/iPhone on google / iPhone doc's to get the full answer.
在Google / iPhone文档上搜索阻止/ NSURL / iPhone以获取完整答案。
只需同步使用NSURLConnection,即可搜索NSURLConnection Synchronous。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.