ios - 有谁知道这里发生了什么?核心数据/iCloud

标签 ios objective-c core-data icloud

所以这里发生的事情是应用程序刚刚收到 NSPersistentStoreDidImportUbiquitousContentChangesNotification,我刚刚调用了

- (void)storesDidUpdate:(NSNotification*)note {
    FLOG(@"storesDidUpdate ");
    [_managedObjectContext mergeChangesFromContextDidSaveNotification:note];

    // Refresh user Interface
    [[NSNotificationCenter defaultCenter] postNotificationName:@"iProjectCoreDataUpdated"
                                                        object:self];

    [self updateDetails];
}

现在应用程序正尝试通过简单地执行以下操作来使用新的文本副本更新 UITextView:

self.detailText.attributedText  = [self.detailItem valueForKey:@"scope"];

其中 detailItem 是在从 iCloud 接收更新之前检索到的 NSManagedObject。

不确定 textContainer 为何提示或提示什么,也不确定为什么要导入日志,因为我已经收到已完成的通知!

奇怪的是,如果我只调用 reloadData,其他 UITableViews 会正确更新。

关于我是否在这里做错了什么有什么想法吗?请注意,如果我不尝试更新 textView,它会正常工作,如果我关闭 View 并返回到它,那么我会得到正确的数据。

此外,当我重新启动应用程序时,所有数据都在那里,没有损坏或任何东西,事实上,尽管 iCloud 的两边都出现问题,但在核心数据存储方面,该应用程序在大多数方面似乎都非常强大!

哦,reloadFetchedResults 有点误导,因为我似乎不需要这样做,所以方法名称是过去的遗留问题,我所做的只是在此调用中刷新 UI 中的值。

2013-10-09 07:25:53.783 MyApp[4509:510b] OpeningViewController.reloadFetchedResults: called 2013-10-09 07:25:53.786 MyApp[4509:510b] InfoDetailViewController.reloadFetchedResults: called in InfoDetailViewController 2013-10-09 07:25:53.788 MyApp[4509:510b] * Assertion failure in void _UIPerformResizeOfTextViewForTextContainer(NSLayoutManager *, UIView *, NSTextContainer *, NSUInteger)(), /SourceCache/UIFoundation/UIFoundation-258/UIFoundation/TextSystem/NSLayoutManager_Private.m:1510 2013-10-09 07:25:53.793 MyApp[4509:510b] -_PFUbiquityRecordImportOperation main: CoreData: Ubiquity: Error importing transaction log: transactionLogLocation: : /var/mobile/Library/Mobile Documents/HHHHHHNNNN~com~mycompany~MyApp/CoreData/New Document/duncangroenewald~simAABC628E-9D5E-58F7-9B8D-0BC724C6D0C8/New Document/W8MckEJ0x2d~HZZIeUH2be6hs41TEOONzKIrCuLcuP4=/6C953E7C-B2AF-47F7-B828-DD062B96415D.1.cdt transactionNumber: 5 , exception: Only run on the main thread! User Info: (null) 2013-10-09 07:25:53.803 MyApp[4509:510b] -_PFUbiquityRecordsImporter operation:failedWithError:: CoreData: Ubiquity: Import operation encountered an error: Error Domain=NSCocoaErrorDomain Code=134060 "The operation couldn’t be completed. (Cocoa error 134060.)" UserInfo=0x16d882c0 {exception=Only run on the main thread!} userInfo: { exception = "Only run on the main thread!"; }. While trying to import the log file at the URL: transactionLogLocation: : /var/mobile/Library/Mobile Documents/HHHHHHNNNN~com~mycompany~MyApp/CoreData/New Document/duncangroenewald~simAABC628E-9D5E-58F7-9B8D-0BC724C6D0C8/New Document/W8MckEJ0x2d~HZZIeUH2be6hs41TEOONzKIrCuLcuP4=/6C953E7C-B2AF-47F7-B828-DD062B96415D.1.cdt transactionNumber: 5 2013-10-09 07:25:53.809 MyApp[4509:510b] * Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Only run on the main thread!' *** First throw call stack: (0x2ff23f53 0x3a6996af 0x2ff23e2d 0x308cb1df 0x3796643d 0x37966185 0x3798f7bb 0x379926f7 0x37992759 0x379b378b 0x379b331f 0x379b2f0d 0x3273b05d 0x129717 0x2fee6121 0x2fe5a317 0x3083edcd 0x308436ab 0x118263 0x2fee6121 0x2fe5a317 0x2fd8c69f 0x2fd8cc93 0x2fd813dd 0x3085197b 0x308f5b35 0x3ab83297 0x3ab8309b 0x3ab83d15 0x3ab83f8d 0x3acbedbf 0x3acbec84) libc++abi.dylib: terminating with uncaught exception of type NSException

编辑: 我在这里发布了一些适用于 iOS 和 OSX 的示例 Core Data/iCloud 应用程序——它们包括用于加载/删除数据以及 iCloud 同步的后台线程。希望解决此处描述的问题。 http://ossh.com.au/design-and-technology/software-development/sample-library-style-ios-core-data-app-with-icloud-integration/

最佳答案

好的,这似乎是解决问题的方法 - 我想我从来没有意识到接收通知会在另一个线程上运行。这是正常行为吗,您收到的所有核心数据通知都是在后台线程上调用的吗?如果是这样,您是否始终必须确保您所做的任何事情都在正确的线程上运行?

- (void)storesDidUpdate:(NSNotification*)note {
    FLOG(@"storesDidUpdate ");
    [_managedObjectContext mergeChangesFromContextDidSaveNotification:note];

    [[NSOperationQueue mainQueue] addOperationWithBlock:^ {
        //Your code goes in here
        LOG(@" Main Thread Code");

        // Refresh user Interface
        [[NSNotificationCenter defaultCenter] postNotificationName:@"CoreDataUpdatedNotification"
                                                        object:self];
    }];

}

编辑:

我终于开始记录我是如何让 Core Data 和 iCloud 非常可靠地工作的,包括处理进出 iCloud 以响应用户更改其使用 iCloud 首选项设置。当我试图弄清楚如何让它工作时,我无法找到一个很好的工作代码解释,所以我希望这对其他人有用。随附该应用程序的工作视频,因此您可以了解它的行为方式以帮助您确定它是否是您想要实现的目标。

http://ossh.com.au/design-and-technology/software-development/

关于ios - 有谁知道这里发生了什么?核心数据/iCloud,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19258126/

相关文章:

ios - 使用静态单元格在 UITableViewController 上添加按钮覆盖

iphone - 网络连接恢复后Iphone是否收到所有推送通知

swift - 预取相关对象的相关对象

ios - 在 Swift 中运行 Core Data Manager 的类初始值设定项

ios - ReactiveCocoa subscribeNext 没有检查

iphone - 实现自定义 UITableViewController 类并避免委托(delegate)警告

iPhone MapKit 是否可以从一系列触摸中映射坐标?

ios - 自定义获取核心数据(快速)

ios - Xcode 找不到我在项目中制作的 .h 文件

ios - 如何在搜索列表中首先获得相同名称的结果 iOS