NSUbiquitousKeyValueStore同步问题 [英] NSUbiquitousKeyValueStore sync issues

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

问题描述

我只有NSUbiquitousKeyValueStore的麻烦,并让它可以在两台设备之间可靠地同步。它开始让我发疯。疯狂。

I'm having nothing but trouble with NSUbiquitousKeyValueStore and getting it to reliably sync across two devices. It's starting to drive me mad. Mad.

我看着我的代码拨打电话:

I watch my code make a call to:

[[NSUbiquitousKeyValueStore defaultStore] setObject:_someData forKey:@"SomeData"];
[[NSUbiquitousKeyValueStore defaultStore] synchronize];

但有时候,数据永远不会出现在另一台设备上。

But more times than not, the data never shows up on the other device.

我看到它在几秒钟内同步,其他时间我等了一个小时,从未见过同步。我将设备插入xcode并开始调试,有时数据会突然弹出,有时则不会。有时确实如此。

I've seen it sync within a few seconds and other times I've waited for an hour and never seen a sync. I plug the devices into xcode and start debugging and sometimes the data suddenly pops up and other times it doesn't. Sometimes it does.

拨打此电话后,退出并重新启动应用程序,如果我阅读它,我会看到旧数据,而不是我认为刚发布的新数据。在同一设备上。

After making this call, quit and restarting the App, I see the old data if I read it, not the new data I supposedly just posted. On the same device.

当应用启动时,我拨打电话:

When the App starts up, I make a call to:

_someData = [[NSUbiquitousKeyValueStore defaultStore] stringForKey:@"SomeData"];

我假设没有需要运行的初始化代码。没有我发现的例子。

I'm assuming there is no init code that needs to be run. No example I've found does.

当它工作时,它运作良好。

When it works, it works quite well.

然后今晚我正在查看设备日志,并在我上次退出后发现此信息(并尝试发送数据):

Then tonight I was looking at the device logs and found this right after my last exit (and attempt to send data):

Jul  8 21:32:03 unknown syncdefaultsd[17296] <Warning>: Error writing storage for com.mycompany.myapp to /private/var/mobile/Applications/4AC8C56E-6060-408B-84F9-F7EC336221D9/Library/SyncedPreferences/com.mycompany.myapp.plist: Error Domain=NSCocoaErrorDomain Code=4 "The operation couldn’t be completed. (Cocoa error 4.)" UserInfo=0xde80d40 {NSFilePath=/private/var/mobile/Applications/4AC8C56E-6060-408B-84F9-F7EC336221D9/Library/SyncedPreferences, NSUnderlyingError=0xde80b20"The operation couldn’t becompleted. No such file or directory"}

该路径不是我的Apps沙箱的有效路径(错误的GUID),所以我想知道这是否是我问题的根源。我在开发过程中删除并重新安装了很多应用程序,所以我想知道是否有一些旧的路径缓存在某个地方并且它正在尝试同步这些数据。有没有办法清除它?

That path is not the valid path from my Apps sandbox (wrong GUID), so I wonder if this is the root of my problems. I do delete and re-install the App a lot during development, so I wonder if there is some old path cached somewhere and it's trying to sync that data. Is there a way to clear it is?

我知道我的所有权利都设置正确,因为它确实有效。

I know all my entitlements are set up correctly since it does work sometimes.

[[NSUbiquitousKeyValueStore defaultStore] synchronize] 返回 YES

有没有其他人看到过此问题或该错误?当我的应用程序启动时以及将数据发送到云时,我还需要做些什么吗?根据文档和示例,它似乎很容易。

Has anyone else seen this problem or that error? Is there something else I need to be doing when my App starts up and when I send data to the cloud? According to the docs and examples, it seems pretty easy.

推荐答案

iCloud键值存储不适用于数据需要定期频繁同步,Apple似乎并不保证这些操作的及时性。 Apple state

iCloud key-value store is not intended for use with data which requires regular frequent synchronization and it appears Apple does not guarantee the timeliness of these operations. Apple states:


键值存储区用于存储不经常更改的数据。如果设备上的应用程序频繁更改键值存储,则系统可以推迟某些更改的同步,以便最小化到服务器的往返次数。应用程序进行更改的频率越高,以后的更改就越有可能延迟,并且不会立即显示在其他设备上。

The key-value store is intended for storing data that changes infrequently. If the apps on a device make frequent changes to the key-value store, the system may defer the synchronization of some changes in order to minimize the number of round trips to the server. The more frequently apps make changes, the more likely it is that later changes will be deferred and not show up on other devices right away.

如果您的应用程序没有立即同步,并且您对此感兴趣是为了加快测试/调试,那么除非您改变技术,否则这似乎是必要的挫折。

If it is okay that your app does not synchronize immediately and your interest in this is to speed testing/debugging then it appears this will be a necessary frustration unless you change your technique.

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

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