iOS应用的基于时间的同步 [英] Time-based syncing for iOS app

查看:134
本文介绍了iOS应用的基于时间的同步的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现一个简单的同步解决方案,在我的应用程序和我的服务器的各种实例之间传播一些设置。对这些设置的更改不常发生,只会发生在客户端。

I'm trying to implement a simple sync solution to propagate a few settings between various instances of my app and my server. Changes to these settings will be infrequent and only occur on the client(s). I would like something reasonably robust without going overboard.

我的策略是跟踪设备上未同步的更改,并在同步时将这些更改发送到服务器。服务器应该能够拒绝针对该设置的先前已知同步之后发生的更改。为了实现这一点,应用程序存储每个设置的更新日期,并且服务器将其与为其相同设置存储的类似字段进行比较。如果客户端的日期早于最新设置同步,服务器知道(来自其他设备),该设置的同步将被拒绝。

My strategy is to track un-synced changes on the device, and when syncing, post these to the server. The server should be able to reject a change that occurred after the previous known sync for that setting. To accomplish this, the app stores an 'Updated' date for each setting, and the server compares this to a similar field it stores for the same setting on its side. If the client's date is prior to the latest setting sync the server knows about (from a different device), the sync for that setting is rejected.

最后(希望)

我最初的想法是发送(在更新的设置旁边)客户端的当前本地日期时间。收到时,服务器将比较客户端的时间与自己的时间,并知道如何调整客户端设置上的更新时间戳。这在原则上听起来合理,但是我如何解决以下两个问题?

My initial thought is to send (alongside the updated setting), the client's current local datetime. On receipt, the server will compare the client's time to its own and know how to adjust the 'updated' timestamp on the client's setting. This sounds reasonable to me in principle, but how can I address the following two issues?


  • 如果客户端设备的时钟在尝试同步之前,设置是否已更新?

  • 谁知道同步请求到达服务器需要多长时间?所以到收到时,客户提供的系统时钟实际上是秒或分钟。

推荐答案

您应该按照 UTC 执行所有操作,以避免时区问题。这不能解决用户时钟设置不正确的问题,所以您可能想要在更新数据时验证服务器以验证实际时间是什么。如果没有网络连接,会有一些条件很难处理。有时,您可以做的最好的办法是检测它们并告诉用户风险。

You should do everything in terms of UTC to avoid time zone issues. That doesn't get round the issue of the users clock just being set incorrectly so you may want to check-in to the server when data is updated to verify what the actual time is. There will be some conditions that are hard to deal with if you have no net connection. Sometimes the best you can do is to detect them and tell the user about the risk.

这篇关于iOS应用的基于时间的同步的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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