【问题标题】:force sync with iCloud through a button通过按钮强制与 iCloud 同步
【发布时间】: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() {

**这里放什么?**

}

谢谢!

【问题讨论】:

    标签: swift icloud cloudkit


    【解决方案1】:

    您似乎正在使用 Core Data 的内置 iCloud 支持。不幸的是,没有公共 API 可以强制进行同步。它是自动处理的,您的应用无法更改时间表。

    【讨论】:

    • 您可能还是想离开 iCloud Core Data。在更新的 iOS 10 文档中,几乎所有内容都已弃用。也许看看 ensembles.io
    • 哦,好吧,我会注意的。 iCloud Core Data 似乎真的很令人沮丧,而且使用起来也很慢。感谢您的建议!我是新手。
    • @TomHarrington,这仍然有效吗?
    • 此问题的 API 已被弃用,不再可用。有一个基于 CloudKit 的新版本,我相信情况相同——同步是自动的,不是由应用程序启动的。但是,它似乎工作得更好,所以这应该不是问题。
    猜你喜欢
    • 2016-01-27
    • 1970-01-01
    • 2011-12-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-13
    • 2016-02-19
    • 1970-01-01
    相关资源
    最近更新 更多