通过按钮强制与 iCloud 同步
force sync with iCloud through a button
我的应用程序使用 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() {
** 在这里放什么?**
}
谢谢!
您似乎在使用 Core Data 的内置 iCloud 支持。不幸的是,没有 public API 强制同步发生。它是自动处理的,您的应用无法更改计划。
我的应用程序使用 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() {
** 在这里放什么?**
}
谢谢!
您似乎在使用 Core Data 的内置 iCloud 支持。不幸的是,没有 public API 强制同步发生。它是自动处理的,您的应用无法更改计划。