我收到了一些用户的崩溃报告。我什至不知道从哪里开始这个。我正在以组列表开头的表格 View 中显示 Assets 库中的图像。我使用以下代码(在主线程上)加载组:
- (ALAssetsLibrary *)library {
if (!_library) {
_library = [[ALAssetsLibrary alloc] init];
}
return _library;
}
- (void)determineGroups {
ALAssetsLibrary *lib = [self library];
[lib enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos | ALAssetsGroupPhotoStream | ALAssetsGroupFaces | ALAssetsGroupLibrary | ALAssetsGroupAlbum | ALAssetsGroupEvent usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
if (group) {
if (!_groups) {
_groups = [[NSMutableArray alloc] init];
}
if ([group numberOfAssets]) {
[group setAssetsFilter:[ALAssetsFilter allPhotos]];
if ([[group valueForProperty:ALAssetsGroupPropertyType] isEqual:@(ALAssetsGroupSavedPhotos)]) {
[_groups insertObject:group atIndex:0];
} else {
[_groups addObject:group];
}
}
} else {
dispatch_async(dispatch_get_main_queue(), ^{
[self.tableView reloadData];
});
}
} failureBlock:^(NSError *error) {
// denied
dispatch_async(dispatch_get_main_queue(), ^{
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
[self.tableView reloadData];
});
}];
}
填充表格 View 时,我想显示每组中的照片数量。我通过在组上调用“numberOfAssets”方法来做到这一点。
大多数情况下,这一切都很好,但在极少数情况下会崩溃。这是具有相关信息的堆栈跟踪之一(线程 5 在主线程忙于获取组中的 Assets 数量时崩溃):
崩溃的线程:5
应用特定信息:
*** 由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“上下文过多。 contextList 中没有空格。
线程 0:
0 核心基金会 0x313a1c42 _CFStringGetLength2 + 26
1 核心基金会 0x313aba41 -[__NSDictionaryM objectForKey:] + 133
2 核心数据 0x312b5d2f -[NSSQLOrderIntermediate generateSQLStringInContext:] + 1283
3 核心数据 0x312018f7 -[NSSQLFetchIntermediate generateSQLStringInContext:] + 515
4 CoreData 0x311fe625 -[NSSQLGenerator newSQLStatementForFetchRequest:ignoreInheritance:countOnly:nestingLevel:] + 425
5 核心数据 0x311fe3ad -[NSSQLAdapter _newSelectStatementWithFetchRequest:ignoreInheritance:] + 509
6 核心数据 0x311fdfc5 -[NSSQLCore newRowsForFetchPlan:] + 117
7 CoreData 0x311fd73f -[NSSQLCore objectsForFetchRequest:inContext:] + 683
8 CoreData 0x311fd205 -[NSSQLCore executeRequest:withContext:error:] + 469
9 CoreData 0x311fc61d -[NSPersistentStoreCoordinator executeRequest:withContext:error:] + 1645
10 核心数据 0x311faf17 -[NSManagedObjectContext executeFetchRequest:error:] + 647
11 PhotoLibraryServices 0x366cd4e5 -[PLManagedObjectContext executeFetchRequest:error:] + 49
12 核心数据 0x3121ad07 _faultBatchAtIndex + 623
13 核心数据 0x3121aa53 -[_PFBatchFaultingArray getObjects:range:] + 143
14 核心数据 0x3121a9c1 -[_PFBatchFaultingArray getObjects:] + 41
15 基础 0x31cfbbe1 _filterObjectsUsingPredicate + 325
16 基础 0x31d01b8d -[NSArray(NSPredicateSupport)filteredArrayUsingPredicate:] + 273
17 PhotoLibraryServices 0x366d86ad +[PLFilteredAlbum filteredIndexesInAlbum:predicate:] + 265
18 PhotoLibraryServices 0x366d8bd1 -[PLFilteredAlbum 过滤索引] + 117
19 PhotoLibraryServices 0x366d8d75 -[PLFilteredAlbum countOfFilteredAssets] + 21
20 AssetsLibrary 0x30ce25d5 __31-[ALAssetsGroup numberOfAssets]_block_invoke_0 + 41
21 CoreData 0x31257fd1 developerSubmittedBlockToNSManagedObjectContextPerform + 89
22 libdispatch.dylib 0x3971d4b7 _dispatch_client_callout + 23
23 libdispatch.dylib 0x397219f7 _dispatch_barrier_sync_f_invoke + 31
24 核心数据 0x31258153 -[NSManagedObjectContext performBlockAndWait:] + 175
25 AssetsLibrary 0x30ce414f -[ALAssetsLibrary _performBlockAndWait:] + 135
26 AssetsLibrary 0x30ce8f59 -[ALAssetsGroupPrivate _performBlockAndWait:] + 177
27 AssetsLibrary 0x30ce254b -[ALAssetsGroup numberOfAssets] + 259
线程 5 崩溃:
0 libsystem_kernel.dylib 0x39804350 __pthread_kill + 8
1 libsystem_c.dylib 0x397b7973 中止 + 95
2 MyApp 0x0074685f ___lldb_unnamed_function30167$$MyApp + 27
3 CoreFoundation 0x3145b57f __handleUncaughtException + 615
4 libobjc.A.dylib 0x39306a65 _objc_terminate() + 129
5 libc++abi.dylib 0x38d5307b safe_handler_caller(void (*)()) + 79
6 libc++abi.dylib 0x38d53114 std::terminate() + 20
7 libc++abi.dylib 0x38d54513 __cxa_throw + 123
8 libobjc.A.dylib 0x393069bf objc_exception_throw + 95
9 CoreFoundation 0x3145b15d +[NSException raise:format:] + 1
10 基础 0x31d30b13 -[NSAssertionHandler handleFailureInFunction:file:lineNumber:description:] + 87
11 PhotoLibraryServices 0x366d0afb __addContextToList_block_invoke_0 + 179
12 libdispatch.dylib 0x3971e11f _dispatch_call_block_and_release + 11
13 libdispatch.dylib 0x39721ecf _dispatch_queue_drain$VARIANT$mp + 143
14 libdispatch.dylib 0x39721dc1 _dispatch_queue_invoke$VARIANT$mp + 41
15 libdispatch.dylib 0x3972291d _dispatch_root_queue_drain + 185
16 libdispatch.dylib 0x39722ac1 _dispatch_worker_thread2 + 85
17 libsystem_c.dylib 0x39752a11 _pthread_wqthread + 361
崩溃来自运行 iOS 6.1.3 的 iPad。该应用程序是使用 iOS 7 GM 的 Base SDK 构建的。该应用程序使用 ARC。
我应该在我的代码中做一些不同的事情来获取组吗?
我是一名优秀的程序员,十分优秀!