[英]1 request vs 2 requests to web service from iphone
I'm working on iPhone app and I'd like to find out what's the best logical way to do the following: 我正在开发iPhone应用程序,我想找出执行以下操作的最佳逻辑方法:
From the app I have to send member_id
and event_id
to web service when user taps a button. 从应用程序中,当用户点击按钮时,我必须将member_id
和event_id
发送到Web服务。 I am using NSURLConnection
and its delegate methods. 我正在使用NSURLConnection
及其委托方法。
There's 2 things that need to happen: 有两件事需要发生:
member_id
and event_id
) need to be inserted in table A on the server ( member_id
和event_id
)都需要插入服务器的表A中 event_id
web service has to respond with array of photos from table B. 基于event_id
Web服务必须使用表B中的照片阵列进行响应。 What is proper logical way of doing this? 这样做的正确逻辑方法是什么?
Keep in mind that I'm only sending member_id
and event_id
in both examples. 请记住,在两个示例中我都只发送member_id
和event_id
。
The first step is to design a web service API. 第一步是设计一个Web服务API。 That may sound simple, but the opposite is the case. 这听起来很简单,但事实恰恰相反。 The "client" never makes such decisions, rather it "adapts". “客户”从不做出这样的决定,而是“适应”。
Once the web service API is set in stone, you try your best to implement the corresponding client API on iOS. 一旦确定了Web服务API,您将尽力在iOS上实现相应的客户端API。
So, your task at the end of the day would possibly be to send a POST request whose content is JSON: 因此,一天结束时您的任务可能是发送内容为JSON的POST请求:
{
"member_id": 1234567,
"event_id": 7654321
}
What that JSON contains is defined by the web service API. JSON包含的内容由Web服务API定义。 Don't bother what the web service is doing with it - just give it what it requires. 不用理会Web服务正在使用它-只需提供它所需的内容即可。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.