Objective c NSUbiquitousKeyValueStoreDidChangeExternallyNotification有时不被调用
我为iCloud键值存储编写了代码Objective c NSUbiquitousKeyValueStoreDidChangeExternallyNotification有时不被调用,objective-c,ios,icloud,Objective C,Ios,Icloud,我为iCloud键值存储编写了代码 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyValueStoreChanged:) name:NSUbiquitousKeyValueStoreDidChan
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyValueStoreChanged:)
name:NSUbiquitousKeyValueStoreDidChangeExternallyNotification
object:nil];
LOG(@"sync");
[[NSUbiquitousKeyValueStore defaultStore] synchronize];
当我删除并重新安装应用程序时,通常会调用observer方法,但有时不会调用
为什么??只是网络问题?我遇到了一个类似的问题,安装后第一次启动时,无论我等待多长时间,都没有触发NSUbiquitousKeyValueStoreDidChangeExternallyNotification。在NSUBiquitousKeyValueStore中设置初始键似乎可以解决这个问题 将观察者添加到默认存储后,我立即调用:
[[NSUbiquitousKeyValueStore defaultStore] setString:@"testValue" forKey:@"testKey"];
[[NSUbiquitousKeyValueStore defaultStore] synchronize];
对于我想要同步的实际数据,我使用了不同的键(即不是testKey)。我发现了一个类似的问题,即无论我等待多长时间,在安装后的第一次重新安装应用程序时,似乎都不会触发NSUbiquitousKeyValueStoreDidChangeExternallyNotification。但是关闭应用程序(而不是将其放在后台)并再次启动它似乎是可行的,并且NSUbiquitousKeyValueStoreDidChangeExternallyNotification从那时起开始正常启动。提交至apple@bugreport.apple.com,12394404-NSUbiquitousKeyValueStore通知不会在第一次应用程序启动时启动