【发布时间】:2016-06-20 02:43:48
【问题描述】:
我的应用使用 iCloud 进行同步。在我的主视图控制器的 viewWillAppear 中:
// Configure persistant store on iCloud
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(TodayViewController.persistentStoreDidChange), name: NSPersistentStoreCoordinatorStoresDidChangeNotification, object: nil)
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(TodayViewController.persistentStoreWillChange(_:)), name: NSPersistentStoreCoordinatorStoresWillChangeNotification, object: managedObjectContext.persistentStoreCoordinator)
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(TodayViewController.recieveICloudChanges(_:)), name: NSPersistentStoreDidImportUbiquitousContentChangesNotification, object: managedObjectContext.persistentStoreCoordinator)
和 viewWillDisappear:
override func viewWillDisappear(animated: Bool) {
NSNotificationCenter.defaultCenter().removeObserver(self, name: NSPersistentStoreCoordinatorStoresDidChangeNotification, object: nil)
NSNotificationCenter.defaultCenter().removeObserver(self, name: NSPersistentStoreCoordinatorStoresWillChangeNotification, object: managedObjectContext.persistentStoreCoordinator)
NSNotificationCenter.defaultCenter().removeObserver(self, name: NSPersistentStoreDidImportUbiquitousContentChangesNotification, object: managedObjectContext.persistentStoreCoordinator)
}
但是,有时同步速度太慢。我希望用户通过点击按钮来强制同步,或者通过向下滑动 tableView 来刷新(重新同步)。我该怎么做?
@IBAction forceSyncButton() {
**这里放什么?**
}
谢谢!
【问题讨论】: