简体   繁体   English

如何在iPhone应用程序Web服务请求中检查服务器端更新

[英]How to check for server side update in iPhone application Web service request

I have kind of Listing application for iPhone application, which always calling a web service to my php server and fetching the data and displaying it onto iPhone screen. 我有一种用于iPhone应用程序的列表应用程序,该应用程序总是调用Web服务到我的php服务器并获取数据并将其显示在iPhone屏幕上。

Now, the thing to consider in this scenario is, my iPhone application everytime requesting on the server and fetching the data. 现在,在这种情况下要考虑的是,我的iPhone应用程序每次在服务器上请求并获取数据时。

But now my requirement is like I want to replace following set of actions with above one : 但是现在我的要求就像我想用上述一个替换以下一组动作:

-> Everytime when my application is launched in iPhone, it should check for the new data at the server`. ->每当我的应用程序在iPhone中启动时,它都应该在服务器上检查新数据。

-> And if server replies "true" then only my iPhone application will made a request to fetch the data. ->如果服务器回复“ true”,则只有我的iPhone应用程序会提出获取数据的请求。

-> In case of "false", my iPhone application will display the data which is already cached in local phone memory. ->如果为“ false”,我的iPhone应用程序将显示已缓存在本地电话内存中的数据。

Now to implement this scenario at server side (which has php, mysql), I am planning with the following solution : 现在要在服务器端(具有php,mysql)实现此方案,我正在计划以下解决方案:

Table : tblNewerData

id newDataFlag
== ============
1      true

Trigger : tgrUpdateNewData 触发器:tgrUpdateNewData

Above trigger will update the tblNewerData -> newDataFlag field on Insert case of my main table. 上面的触发器将更新主表的“插入”大小写上的tblNewerData-> newDataFlag字段。

And every time my iPhone app will request for tblNewerData->newDataFlag field, and if it found true then only it will create new request, and if it founds false then the cached version of data will be displayed. 并且每当我的iPhone应用程序请求tblNewerData-> newDataFlag字段时,如果找到true,则只有它会创建新请求,如果发现false,则将显示缓存的数据版本。

So, I want to know that, is it the correct way to do so ? 所以,我想知道,这是正确的方法吗? or else any other smart option available ? 还是有其他可用的智能选项?

Thanks in advance. 提前致谢。

You should consider making the field a counter instead. 您应该考虑将该字段设置为计数器。 Every time any change is made to your database, the counter is increased. 每次对数据库进行任何更改时,计数器都会增加。

Now when the iPhone connects, it will compare that current counter with the counter from the previous fetch. 现在,当iPhone连接时,它将把当前计数器与上一次获取的计数器进行比较。 If the counter has changed, it will fetch updated data. 如果计数器已更改,它将获取更新的数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM