简体   繁体   English

CoreData和iCloud; 如何跟踪上次保存到云的设备?

[英]CoreData and iCloud; how can I track which device last saved to the cloud?

I have a CoreData app (using https://github.com/lhunath/UbiquityStoreManager ), backed by iCloud. 我有一个由iCloud支持的CoreData应用程序(使用https://github.com/lhunath/UbiquityStoreManager )。 In one use case a user with a local store enables iCloud (where data already exists). 在一个用例中,拥有本地存储的用户启用了iCloud(已存在数据)。 I want to prompt the user to make a decision of whether to migrate the local data to iCloud or just use the iCloud version. 我想提示用户做出将本地数据迁移到iCloud还是仅使用iCloud版本的决定。 As part of this, I'd like to display the device name and last sync date of the version in iCloud. 为此,我想在iCloud中显示设备名称和该版本的上次同步日期。

I've been tinkering around with my NSPersistentStore's metadata, but that doesn't appear to get synced to iCloud. 我一直在修改NSPersistentStore的元数据,但这似乎并没有同步到iCloud。

Any suggestions? 有什么建议么?

您可以使用iCloud的键值存储来存储设备名称和上次同步的日期。

do a metadata query on the iCloud files and check the most recent transaction log file in iCloud. 在iCloud文件上执行元数据查询,并检查iCloud中的最新事务日志文件。 See the link below for a sample app that uses this approach to check whether the app is properly synchronised with iCloud. 请参阅下面的链接,获取使用此方法检查应用程序是否与iCloud正确同步的示例应用程序。
http://ossh.com.au/design-and-technology/software-development/sample-library-style-ios-core-data-app-with-icloud-integration/ http://ossh.com.au/design-and-technology/software-development/sample-library-style-ios-core-data-app-with-icloud-integration/

EDIT: I just realised I don't get the actual device name, but once you have found the most recent log file then use this to get the device. 编辑:我只是意识到我没有得到实际的设备名称,但是一旦找到了最新的日志文件,就可以使用它来获取设备。 Just be aware this call may be expensive. 请注意,此调用可能会很昂贵。

NSFileVersion *openedVersion = [NSFileVersion currentVersionOfItemAtURL:fileURL];
    return openedVersion.localizedNameOfSavingComputer;

My no doubt unpopular suggestion is "don't". 毫无疑问,我不受欢迎的建议是“不要”。 Trying to determine what is in iCloud at any given time puts you on pretty shaky ground. 尝试在任何给定时间确定iCloud中的内容会让您处于不稳定的境地。 You may be able to get it to work most of the time, but there will always be circumstances where it breaks down. 您也许可以使它在大多数时间都能正常工作,但是在某些情况下总是会发生故障。

If you really must import some data when first enabling iCloud, I suggest just always importing the data, and then deduping later as the iCloud data comes in. As ugly as it sounds, that's the only approach really guaranteed to work with Apple's approach. 如果确实在首次启用iCloud时确实必须导入一些数据,我建议只导入数据,然后在iCloud数据传入后再进行重复数据删除。听起来很丑陋,这是保证与Apple兼容的唯一方法。

It is worth taking a look at other Core Data sync frameworks like TICDS and Ensembles. 值得一看其他核心数据同步框架,例如TICDS和Ensembles。 They take a more sane approach to data identity, which means you can avoid the whole deduping step. 他们对数据身份采取更为明智的方法,这意味着您可以避免整个重复数据删除步骤。 (Disclosure: I develop Ensembles) (公开:我开发了乐团)

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

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