ios – 核心数据iCloud Sync确实更改了商店通知不刷新UI

ios – 核心数据iCloud Sync确实更改了商店通知不刷新UI,第1张

概述我无法处理这个问题,我正在尝试将iCloud和Core Data集成到我的应用程序中,并且我坚持使用iCloud同步部分. 我的完整场景: >本地核心数据存储以初始数据为种子 >稍后,应用程序会询问用户有关iCloud或本地数据存储的信息 >如果用户选择iCloud,则当前本地存储将迁移到iCloud存储 >迁移后,将使用iCloud Store重新加载上下文和持久性存储协调器 >从新上下文中重新 我无法处理这个问题,我正在尝试将iCloud和Core Data集成到我的应用程序中,并且我坚持使用iCloud同步部分.

我的完整场景:

>本地核心数据存储以初始数据为种子
>稍后,应用程序会询问用户有关iCloud或本地数据存储的信息
>如果用户选择iCloud,则当前本地存储将迁移到iCloud存储
>迁移后,将使用iCloud Store重新加载上下文和持久性存储协调器
>从新上下文中重新获取数据(此处为麻烦)

如果我们拿走有关迁移的讨论并专注于使用iCloud加载持久性商店协调器,我认为问题与此有关
NSPersistentStoreCoordinatorStoresDIDChangeNotification事件.

我只是不明白.在我阅读的每篇文章中,我都看到了类似的内容:“在这里重新加载UI”.但它对我不起作用.

重新加载协调员功能

func configureContext() -> NSManagedobjectContext? {    // Create the coordinator and context    let coordinator = NSPersistentStoreCoordinator(managedobjectModel: self.managedobjectModel)    //remove all observers from "prevIoUs" coordinator    deregisterForStoreChanges()    //and register them for new one    registerObservers(persistentStoreCoordinator: coordinator)    do {        //storesettings.url = applicationdocumentsDirectory.URLByAppendingPathComponent("iCloud.sqlite")        //storesettings.options = [NSPersistentStoreUbiquitousContentnameKey:"iCloudProject"]        try coordinator.addPersistentStoreWithType(NSsqliteStoreType,configuration: nil,URL: storesettings.url,options: storesettings.options)    } catch {        //Here was standard error handler I dIDn't changed it,but removed for Listing        abort()    }    persistentStoreCoordinator = coordinator    let managedobjectContext = NSManagedobjectContext(concurrencyType: .MainQueueConcurrencyType)    managedobjectContext.persistentStoreCoordinator = coordinator    //not quite sure about the next string,dIDn't test it yet    managedobjectContext.mergePolicy = NSMergePolicy(mergeType:NSMergePolicyType.MergeByPropertyStoreTrumpMergePolicyType )    //trIEd to refetch my records here but,with no luck.    //refetchUIRecords()    return managedobjectContext}

还有我的NSPersistentStoreCoordinatorStoresDIDChangeNotification事件函数

func persistentStoreCoordinatorDIDChangeStores(notification:NSNotification){    if notification.userInfo?[NSAddedPersistentStoresKey] != nil {        print("-----------------------")        print("ADDED")        print("-----------------------")        //deduplicateRecords()        //if iCloud -> refetch UI        if NSUserDefaults.standardUserDefaults().boolForKey("iCloud"){            self.createTimer()        }    }    print("DID Change")}

创建计时器功能只是在实际重新获取和刷新UI之前等待1秒的功能.

问题

当我们从我的场景到达第4步,并调用configureContext函数时,
我在控制台中看到了这个:

2016-04-12 13:31:27.749 TestingiCloudProject[2052:1142902] -[PFUbiquitySwitchboardEntryMetadata setUselocalstorage:](898): CoreData: Ubiquity:  mobile~567404C0-9D84-4C07-A0F8-D25832CB65D8:iCloudProjectUsing local storage: 1 for new NSfileManager current token <ef7a917f bca47ecf 5d58862d cbe9998d 7e53e5ea>DID ChangeDID Change-----------------------ADDED-----------------------TimerDID ChangeRefetchRefetching...Number of records after fetch: 1 //must be more than 1 2016-04-12 13:31:30.090 TestingiCloudProject[2052:1143055] -[PFUbiquitySwitchboardEntryMetadata setUselocalstorage:](898): CoreData: Ubiquity:  mobile~567404C0-9D84-4C07-A0F8-D25832CB65D8:iCloudProjectUsing local storage: 0 for new NSfileManager current token <ef7a917f bca47ecf 5d58862d cbe9998d 7e53e5ea>

正如你可以看到我的获取请求在使用本地存储之前执行:0这就是为什么我从本地存储(1条记录)接收记录而不是iCloud(包含多于1条)的记录.

我不明白何时重新获取我的记录.对于想要了解更多有关Core Data和iCloud的所有人,我从great source中获取计时器部分.
但是,1秒钟没有投入,2秒是我想要的工作,但是如果iCloud商店比我的更大,或者网络连接会比我的更糟糕,我不认为计时器就是这样.

我希望有人已经面临这个微不足道的问题.

编辑

我没有从Apple dev论坛找到任何帮助,所以我激活了我的代码技术支持令牌,我希望他们可以帮助我.一旦我解决了我的问题,我就会写一个答案.但是,如果您读过这个问题的人知道可能的答案,请立即发布.

解决方法 每当从无处不在的内容存储库导入数据时,持久性存储协调器会触发另一个通知NSPersistentStoreDIDimportUbiquitousContentChangesNotification.您可以在此处将更改与NSManagedobjectContext合并.

When the ubiquity container receives changes from iCloud,Core Data posts an NSPersistentStoreDIDimportUbiquitousContentChangesNotification notification. This notification’s userInfo dictionary is structured similarly to that of an NSManagedobjectContextDIDSaveNotification notification except for that it contains NSManagedobjectID instances rather than NSManagedobject instances. Therefore you can merge in changes from other peers in the same way that you merge changes from other managed object contexts. Call mergeChangesFromContextDIDSaveNotification: on your managed object context,passing in the notification object posted by Core Data.

https://developer.apple.com/library/ios/documentation/DataManagement/Conceptual/UsingCoreDataWithiCloudPG/UsingSQLiteStoragewithiCloud/UsingSQLiteStoragewithiCloud.html

总结

以上是内存溢出为你收集整理的ios – 核心数据iCloud Sync确实更改了商店通知不刷新UI全部内容,希望文章能够帮你解决ios – 核心数据iCloud Sync确实更改了商店通知不刷新UI所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1003089.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-22
下一篇 2022-05-22

发表评论

登录后才能评论

评论列表(0条)

保存