我为 iCloud key-value Store 编写了代码
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyValueStoreChanged:)
name:NSUbiquitousKeyValueStoreDidChangeExternallyNotification
object:nil];
LOG(@"sync");
[[NSUbiquitousKeyValueStore defaultStore] synchronize];
当我删除应用程序并重新安装它时,通常会调用观察者方法,但有时不会调用。
为什么?只是网络问题?
最佳答案
我有一个类似的问题,无论我等了多久,NSUbiquitousKeyValueStoreDidChangeExternallyNotification 都没有在安装后的第一次启动时触发。在 NSUBiquitousKeyValueStore 中设置一个初始 key 似乎可以解决这个问题。
将观察者添加到默认存储后,我立即调用:
[[NSUbiquitousKeyValueStore defaultStore] setString:@"testValue" forKey:@"testKey"];
[[NSUbiquitousKeyValueStore defaultStore] synchronize];
我对要同步的实际数据使用不同的 key (即不是 testKey)。
关于objective-c - 有时不调用 NSUbiquitousKeyValueStoreDidChangeExternallyNotification,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12635960/