无需 [[UIDevice] uniqueIdentifier] 即可安全实现三路和四路设备同步?

发布于 2024-12-13 17:38:56 字数 622 浏览 0 评论 0原文

事实证明,切换到自定义生成的设备 UUID 确实是一场噩梦!我希望有人以前遇到过这个问题并且可能知道处理它的方法。

假设用户的应用程序具有 500,000(小)记录的数据集,简单地复制设备的整个数据库并合并它们是不可行的。用户已将此应用程序安装在以下设备上:

  1. iPhone、
  2. MacBook
  3. Android 平板电脑。

当连接到同一物理网络时,每个设备都可以看到彼此并可以发起同步。 实现三向数据同步(不依赖于中央服务器或互联网连接)。

  1. 每个设备都会保存一个带有时间戳的更改列表。
  2. 每个设备都知道它上次与其他两个设备同步的时间。
  3. 当一个设备看到另一个设备时,它会发送自上次与该设备通信以来的所有已知更改。
  4. 如果发现新设备,只需发送所有输入的数据就可以了。

如果用户备份自己的 iPhone 或 iPad,然后将其恢复到另一部 iPhone 或 iPad 上,就会出现问题。在这种情况下,我们最终会得到一个用户在本地网络上拥有两台具有相同 UUID 的设备。更新最终(随机)发送到一台或另一台具有相同标识的设备。

我知道我们现在可以继续使用设备唯一标识符,但我担心一旦它消失会发生什么!

Switching to custom generated device UUID's is turning out to truly be a nightmare! I am hoping someone has come across this before and might know a way to deal with it.

Assume a user has an application with a data set of 500,000 (small) records, its not feasible to simply copy the entire db of a device and merge them. A user has this application installed on an:

  1. iPhone,
  2. MacBook
  3. Android tablet.

When connected to the same physical network, each device can see each other and can initiate a synchronisation.
To achieve three way data synchronisation (that does not depend on a central server or an internet connection).

  1. Each device keeps a list of timestamped changes.
  2. Each device knows the last time it synchronised with each of the other two devices.
  3. When a device sees another device, it sends through all known changes since the last time they spoke to that device.
  4. If a new device is discovered, no problem just send through all data ever entered.

The problem comes along if a user backs up their iphone or ipad, and restores it onto another iphone or ipad. Under this scenario we are ending up with a user that has two devices on the local network with the same UUID. Updates end up (randomly) going to one or the other identically identified devices.

I know we can continue to use the device unique identifier for now, but I am worried whats going to happen once its gone!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

似最初 2024-12-20 17:38:56

应用程序启动时,您在应用程序文档文件夹中搜索名为 udid.txt 的文件。如果此文件不可用,请创建它并生成您的自定义 UDID,并将其保存到此文件中。使用以下函数向该文件添加标志,以将其从备份和同步例程中排除。

#include <sys/xattr.h>
- (void) AddSkipBackupAttributeToFile: (NSURL*) url
{
  u_int8_t b = 1;
  setxattr([[url path] fileSystemRepresentation], "com.apple.MobileBackup", &b, 1, 0, 0);
}

此解决方案的问题是用户可能会使用 iPhoneExplorer 或类似的工具来更改 UDID。尝试加密或隐藏文件以防止他这样做。

注意:仅适用于 iOS 5.0.1。

On application start you search for a file in the applications documents folder called udid.txt. If this file is not available create it and generate your custom UDID, save it to this file. Use the following function to add a flag to this file, to exclude it from the backup and sync routines.

#include <sys/xattr.h>
- (void) AddSkipBackupAttributeToFile: (NSURL*) url
{
  u_int8_t b = 1;
  setxattr([[url path] fileSystemRepresentation], "com.apple.MobileBackup", &b, 1, 0, 0);
}

The problem with this solution is that a user might use iPhoneExplorer or something similar to change the UDID. Try to encrypt or hide the file to prevent him from doing this.

Note: Works only since iOS 5.0.1.

丿*梦醉红颜 2024-12-20 17:38:56

您可以将生成的设备 UDID 存储在 Caches 目录中的文件中,该文件不会在该目录中备份。当备份恢复到新设备上时,数据库将存在,但不会有 UDID 文件。在本例中创建一个新的 UDID;其他实例会将其视为新实例,并且可以推送任何最近的更改。您可能想要更改逻辑,以便其他实例将查询新 UDID 上的时间戳,而不是假设新实例完全为空。

iOS 5.0之前,您的UDID文件不会被系统自动删除。然而,在 iOS 5.0 中,您需要忍受这样的事实:它可能会在磁盘空间不足的情况下被清除。如果发生这种情况,只需按照恢复到新设备时的相同步骤操作即可:创建新的 UDID;其他实例会将其视为新实例并推送最近的更改。

正如Floix所说,iOS 5.0.1(尚未发布)中有一个新机制,可以让您指定既不备份也不清除文件。

You can instead store your generated device UDID in a file in the Caches directory, where it will not be backed up. When a backup is restored onto a new device, the database will be present but there will be no UDID file. In this case create a new UDID; the other instances will see this as a new instance and can push any recent changes across. You might want to change the logic so the other instances will query the timestamp on a new UDID instead of assuming the new instance is totally empty.

Before iOS 5.0, your UDID file will not be automatically deleted by the system. However in iOS 5.0 you will need to put up with the fact that it may get purged in low disk space situations. If that happens, just follow the same procedure as when restored onto a new device: create a new UDID; the other instances will see this as a new instance and push recent changes across.

As Floix said, there is a new mechanism in iOS 5.0.1 (yet to be released) which will let you specify that the file should be neither backed up nor purged.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文