简体   繁体   English

使用键值将字典发送到iCloud

[英]Send Dictionary to iCloud using Key-value

I am using this code for writing a dictionary to iCloud. 我正在使用此代码向iCloud编写字典。

 [[NSUbiquitousKeyValueStore defaultStore]
     setDictionary:dictCloudTables forKey:@"Tables"];

 [[NSUbiquitousKeyValueStore defaultStore] synchronize];

And i am fetching dictionary from cloud using this code: 我正在使用此代码从云中获取字典:

 dictCloudTables = [[[NSUbiquitousKeyValueStore defaultStore]
                      dictionaryForKey:@"Tables"] mutableCopy];

It always gives me dictionary that i have inserted for the very first time. 它总是给我我第一次插入的字典。

Is there anything wrong with my code? 我的代码有什么问题吗?

I don't see anything obviously wrong with the code (except you don't check the return value of synchronise ). 我看不出有什么明显错误的代码(除非你不检查返回值synchronise )。 I think what might be wrong is your expectation of what should happen. 我认为可能是您对应该发生的事情有期望。 Here's an extract from the documentation: 以下是文档摘录:

This method does not force new keys and values to be written to iCloud. 此方法不会强制将新键和值写入iCloud。 Rather, it lets iCloud know that new keys and values are available to be uploaded. 而是让iCloud知道可以上传新的键和值。 Do not rely on your keys and values being available on other devices immediately. 不要依赖于其他设备上立即可用的键和值。

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

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