如何通知iCloud同步已完成,我怎么知道我有新数据要显示? 例如,应用程序有一些数据。应用程序已被删除并重新安装。当我用openWithCompletionHandler打开文档时,它会在同步完成之前调用我的块。
答案 0 :(得分:-1)
在viewDidLoad方法中,
//Catch any changes
NSUbiquitousKeyValueStore *store = [NSUbiquitousKeyValueStore defaultStore];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(storeDidChange:)
name:NSUbiquitousKeyValueStoreDidChangeExternallyNotification
object:store];
[[NSUbiquitousKeyValueStore defaultStore] synchronize];
实施方法,
- (void)storeDidChange:(NSNotification *)notification
{
// Retrieve the changes from iCloud
_notes = [[[NSUbiquitousKeyValueStore defaultStore] arrayForKey:@"AVAILABLE_NOTES"] mutableCopy];
}
也查看此链接, http://www.appcoda.com/icloud-programming-ios-intro-tutorial/