iPhone RESTful Web服务 [英] iphone RESTful webservices

查看:67
本文介绍了iPhone RESTful Web服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

甚至不确定标题是否正确,但是,我要尝试使用的是标准NSURLConnection类来处理来自调用Web服务的响应.我正在使用POST方法更新数据库,并使用GET方法从数据库中检索行.我的问题是,这两个动作可能同时发生,因此处理请求的方法可能会相互接续.换句话说,在我的"connection didReceiveData"方法中,根据我要处理的是GET还是POST请求的响应,我在代码中有2条路径.

Not even sure if the title is correct, however, what I'm trying to do is use the standard NSURLConnection class to handle responses from calling my webservice. I am using the POST method to update a database and the GET method to retrieve rows from the database. The problem I have is that these 2 actions may occur simultaneously so that the methods to handle the request may step on each other. In other words in my "connection didReceiveData" method I have 2 paths through the code depending on whether I'm handling a response from a GET or POST request.

我跟踪一个名为requestType的实例变量正在处理哪个请求.问题在于,由于同时执行请求,因此在GET完成之前将实例变量从GET更改为POST(反之亦然).我的问题是在这种情况下如何维护2个单独的请求?我是否同步请求?有没有办法让线程在这里工作?我是否为每个请求创建2个单独的对象,并且在"didRecieveData"查询中具有处理哪个对象的逻辑?任何帮助将不胜感激!

I keep track on which request in being processed by an instance variable called requestType. The problem is that since the requests are being executed simultaneously the instance variable is being changed from GET to POST before the GET completes (or vice-versa). My question is how do I maintain 2 separate requests in this scenario? Do I synchronize the requests? Is there a way for threads to work here? Do I create 2 separate objects for each of the requests and have the logic in "didRecieveData" query for which object is being processed? Any help would be much appreciated!!

推荐答案

在我们的一个应用程序中发生了类似问题.解决方案包括创建一个代表Web服务调用的类,负责调用其自己的url,加载其自身的数据等.调用类具有一个负责解析响应的委托(在我们的示例中为Web服务控制器).伤口变得相当复杂,但避免了NSURLConnections彼此踩踏的问题.

Dealt with a similar issue in one of our apps. The solution involved creating a class that represents a webservice call, responsible for calling its own url, loading its own data, etc. The call class had a delegate that would handle parsing the responses (in our case, a web service controller). Wound up getting rather complicated, but prevented the issue of NSURLConnections stepping on each other.

这篇关于iPhone RESTful Web服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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