- objective-c - iOS 5 : Can you override UIAppearance customisations in specific classes?
- iphone - 如何将 CGFontRef 转换为 UIFont?
- ios - 以编程方式关闭标记的信息窗口 google maps iOS
- ios - Xcode 5 - 尝试验证存档时出现 "No application records were found"
我在 iOS 8.1 上遇到 CoreData 并发问题。
我得到了崩溃的以下堆栈跟踪:
NSInternalInconsistencyException - 无效的 rowCache 行为 nil
0 CoreFoundation 0x0000000183b6659c __exceptionPreprocess + 132
1 libobjc.A.dylib 0x00000001942640e4 objc_exception_throw + 56
2 CoreData 0x000000018385b8b8 -[NSSQLCore _newRowCacheRowForToManyUpdatesForRelationship:rowCacheOriginal:originalSnapshot:value:added:deleted:sourceRowPK:properties:sourceObject:newIndexes:reorderedIndexes:] + 6668
3 CoreData 0x00000001838fbea0 -[NSSQLCore recordToManyChangesForObject:inRow:usingTimestamp:inserted:] + 2604
4 CoreData 0x0000000183857638 -[NSSQLCore prepareForSave:] + 1052
5 CoreData 0x00000001838569b4 -[NSSQLCore saveChanges:] + 520
6 CoreData 0x000000018381f078 -[NSSQLCore executeRequest:withContext:error:] + 716
7 CoreData 0x00000001838e6254 __65-[NSPersistentStoreCoordinator executeRequest:withContext:error:]_block_invoke + 4048
8 CoreData 0x00000001838ed654 gutsOfBlockToNSPersistentStoreCoordinatorPerform + 176
9 libdispatch.dylib 0x00000001948a936c _dispatch_client_callout + 12
10 libdispatch.dylib 0x00000001948b26e8 _dispatch_barrier_sync_f_invoke + 72
11 CoreData 0x00000001838e0cb4 _perform + 176
12 CoreData 0x000000018381ec34 -[NSPersistentStoreCoordinator executeRequest:withContext:error:] + 296
13 CoreData 0x0000000183845400 -[NSManagedObjectContext save:] + 1280
这个崩溃发生在几个地方(大约 20 个),但在我的数据导入功能中最为突出,该功能导入了 1000 条记录并每 100 条保存一次。
关于我的 CoreData 设置的一些注意事项:
performBlock:
发生所有这些保存的代码具有以下基本模式:
[backgroundContext performBlock:^{
...
NSArray *result = [backgroundContext fetch...];
...
if ([backgroundContext save:&error]) { // <-- App is crashing here
}
}];
据我所知,backgroundContext
后面的 NSPersistentStore
不应该有任何并发问题,但这就是崩溃告诉我的。
此外,这种情况只发生在不到 0.02% 的用户群中。这种情况非常罕见(我无法重现),但用户无法在不删除并重新安装应用程序的情况下从中恢复。它会一直为他们打开和崩溃。
请注意,这仅适用于 64 位 iOS 8.1.X - iOS 7.X 和 8.0.X 不会出现此行为,而且我在 iPhone 5s 之前的任何设备上都没有看到它。
说明:删除持久性存储可以为所有用户修复此问题。这似乎表明这不是并发问题。
商店和上下文的创建。
[_persistenStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType
configuration:nil
URL:[DatabaseManager storeURL]
options:@{NSMigratePersistentStoresAutomaticallyOption:@YES,
NSInferMappingModelAutomaticallyOption:@YES}
error:&error];
创建上下文
_backgroundContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSPrivateQueueConcurrencyType];
[_backgroundContext setMergePolicy:NSMergeByPropertyObjectTrumpMergePolicy];
[_backgroundContext setPersistentStoreCoordinator:_persistenStoreCoordinator];
if ([_backgroundContext respondsToSelector:@selector(setName:)]) {
[_backgroundContext setName:@"DatabaseManager.BackgroundQueue"];
}
_mainContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSMainQueueConcurrencyType];
[_mainContext setMergePolicy:NSMergeByPropertyObjectTrumpMergePolicy];
[_mainContext setPersistentStoreCoordinator:_persistenStoreCoordinator];
if ([_mainContext respondsToSelector:@selector(setName:)]) {
[_mainContext setName:@"DatabaseManager.MainQueue"];
}
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(mainContextDidSave:)
name:NSManagedObjectContextDidSaveNotification
object:_mainContext];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(backgroundContextDidSave:)
name:NSManagedObjectContextDidSaveNotification
object:_backgroundContext];
监听变化
- (void) mainContextDidSave:(NSNotification *)notification
{
[_backgroundContext performBlock:^{
[self->_backgroundContext mergeChangesFromContextDidSaveNotification:notification];
}];
}
- (void) backgroundContextDidSave:(NSNotification*)notification
{
[_mainContext performBlock:^{
NSArray* updated = [notification.userInfo valueForKey:NSUpdatedObjectsKey];
// Fault all objects that will be updated.
for (NSManagedObject* obj in updated) {
NSManagedObject* mainThreadObject = [self->_mainContext objectWithID:obj.objectID];
[mainThreadObject willAccessValueForKey:nil];
}
[self->_mainContext mergeChangesFromContextDidSaveNotification:notification];
}];
}
如何在每个上下文中执行代码。我将一个 block 传递到这里:
- (void)executeBackgroundOperation:(void (^)(NSManagedObjectContext *))operation {
NSAssert(operation, @"No Background operation to perform");
[_backgroundContext performBlock:^{
operation(self->_backgroundContext);
}];
}
- (void)executeMainThreadOperation:(void (^)(NSManagedObjectContext *))operation {
NSAssert(operation, @"No Main Thread operation to perform");
[_mainContext performBlock:^{
operation(self->_mainContext);
}];
}
崩溃报告中仅有的其他线程中有 lock
是两个 Javascript 线程,如下所示:
0 libsystem_kernel.dylib 0x3a77cb38 __psynch_cvwait + 24
1 libsystem_pthread.dylib 0x3a7fa2dd pthread_cond_wait + 38
2 libc++.1.dylib 0x39a11e91 _ZNSt3__118condition_variable4waitERNS_11unique_lockINS_5mutexEEE + 34
3 JavaScriptCore 0x2dcd4cb5 _ZN3JSC8GCThread16waitForNextPhaseEv + 102
4 JavaScriptCore 0x2dcd4d19 _ZN3JSC8GCThread12gcThreadMainEv + 50
5 JavaScriptCore 0x2db09597 _ZN3WTFL19wtfThreadEntryPointEPv + 12
6 libsystem_pthread.dylib 0x3a7f9e93 _pthread_body + 136
7 libsystem_pthread.dylib 0x3a7f9e07 _pthread_start + 116
8 libsystem_pthread.dylib 0x3a7f7b90 thread_start + 6
最佳答案
您认为这可能不是并发问题是正确的。当迁移未正确完成时,删除和安装应用程序通常会修复核心数据错误。
如果您发布了应用程序,更改了核心数据模型,然后发布了更新(没有迁移),这可能是您崩溃的根源。
按照本教程进行操作,看看它是否能解决您的问题。 http://www.raywenderlich.com/27657/how-to-perform-a-lightweight-core-data-migration
关于ios - 崩溃 : NSInternalInconsistencyException - Invalid rowCache row is nil,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28463538/
我的 iOS 应用程序出现奇怪的错误。从昨天开始一切都运行良好,今天我对一个与 AppDelegate 无关的 View Controller 做了一些改进,当我试图测试我在模拟器上所做的更改时,我得
所以,我正在尝试一下 iOS 编程。时间不多,但我已经推迟学习太久了。但我被这个奇怪的问题困扰了两天。当我尝试将单元格添加到我的 collectionView 时,出现以下错误。 'NSInterna
我的应用程序发生了奇怪的崩溃(仅限 iPad 的 9.x),我不确定如何调试它,因为日志无助于发现正在发生的事情。 最奇怪的是日志显示Auto layout internal error ,但我的应用
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid updat
我想在 swift 中创建一个弹出窗口,并在用户单击按钮时显示它。我不使用 Storyboard , View 是通过编程创建的。 class CreateNoticePopupViewControl
我在仅限 iOS 12 的 crashlytics 上遇到此崩溃。 有人知道这是什么吗?看起来与推送通知相关,但我们的应用中还没有。 致命异常:NSInternalInconsistencyExcep
我已经阅读了有关此错误的所有内容,但仍然无法确定为什么它会在我的应用程序中发生。 使用后台上下文保存多个 Core Data 对象时出现以下错误: *** 由于未捕获的异常“NSInternalInc
我正在尝试从 UITableView 中删除行 -(void) closePickerViewRow:(id) sender { if(self.pickerIsShown && [self.
我在 IOS 上使用 PhoneGap 2.9.0 并为 iPhone5 构建应用程序。 我正在尝试更改启动画面,我遵循了 phonegap 解释 我的行动: 1. 在 iPhone project
对,我有 5 次观看。其中一个 View 称为 RecordViewController。 (RecordViewController 导致错误)我可以很好地切换 View 。但是一旦我进入记录 Vi
在搜索解决方案后我无法解决这个问题,我有这段代码来列出核心数据中的数据: import UIKit import CoreData class ViewControllerClass: UITable
我遇到了一个问题,我有一个忘记密码选项,我在其中放置了一个带有输入字段的 UIAlertView。 UIAlertView *alertView = [[UIAlertView alloc] init
我想用 Objective-C 做一个带有表搜索的 iOS 应用程序。我试过这个项目: https://github.com/versluis/Table-Search-2015 现在我尝试在导航 V
我在 View Controller 之间切换时遇到问题。 我的 md360AppDelegate.h header 如下所示 #import @class md360ViewController;
更新方法: override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingS
每当我尝试使用 AVPlayer 从 url 流式传输歌曲时,我都会收到 NSInternalInconsistencyException 错误。我在结构上制作了一个全局流播放器,以便我的流播放器可以
我正在尝试向我的应用添加容器 View 。但是,它不断崩溃并出现以下错误: 'NSInternalInconsistencyException',原因:'containerView 是必需的。' 我做
尝试保留(更新)标识对象 (persistIdentity:error:) 时版本不匹配失败。对象版本=1229,持久版本=1230。 #10. Crashed: com.twitter.crashl
更新:看来我设法识别了单元格,所以原来的问题解决了。但是现在,截断相同的代码后,出现以下错误: 2012-10-31 15:21:41.857 Laktase[22658:11603] -[NSMan
我有这段代码试图在后台获取 HealthKit 数据。当我第一次运行该应用程序时,代码运行良好,但如果我手动执行后台提取(使用调试命令),我会抛出一个异常并显示一个错误,内容为 reason: 'th
我是一名优秀的程序员,十分优秀!