SIGSEGV:零星的崩溃问题

时间:2017-06-09 09:10:54

标签: ios objective-c core-data xcode8 crash-reports

这是我第一次尝试解决iOS应用中的崩溃问题。在这里分享一些崩溃日志。

Exception Type:  SIGSEGV
Exception Codes: SEGV_ACCERR at 0x97ad6beb8
Crashed Thread:  11

Application Specific Information:
objc_msgSend() selector name: length

这是我的第11个帖子。

Thread 11 Crashed:
0   libobjc.A.dylib                      0x0000000180558150 objc_msgSend + 16
1   Foundation                           0x00000001824f3f60 -[NSString compare:] + 28
2   Foundation                           0x00000001824d88e0 _NSCompareObject + 60
3   CoreFoundation                       0x0000000181a99bd0 __CFSimpleMergeSort + 88
4   CoreFoundation                       0x0000000181a99c60 __CFSimpleMergeSort + 232
5   CoreFoundation                       0x0000000181a99c60 __CFSimpleMergeSort + 232
6   CoreFoundation                       0x0000000181a99c60 __CFSimpleMergeSort + 232
7   CoreFoundation                       0x0000000181a99c60 __CFSimpleMergeSort + 232
8   CoreFoundation                       0x0000000181a99c60 __CFSimpleMergeSort + 232
9   CoreFoundation                       0x0000000181a99c60 __CFSimpleMergeSort + 232
10  CoreFoundation                       0x0000000181a99c60 __CFSimpleMergeSort + 232
11  CoreFoundation                       0x0000000181a99c60 __CFSimpleMergeSort + 232
12  CoreFoundation                       0x0000000181a99c60 __CFSimpleMergeSort + 232
13  CoreFoundation                       0x0000000181a99c60 __CFSimpleMergeSort + 232
14  CoreFoundation                       0x0000000181a99c60 __CFSimpleMergeSort + 232
15  CoreFoundation                       0x00000001819c585c CFSortIndexes + 460
16  CoreFoundation                       0x00000001819c6f9c CFMergeSortArray + 372
17  Foundation                           0x00000001824d80e8 _sortedObjectsUsingDescriptors + 568
18  Foundation                           0x00000001825c64e0 -[NSSet(NSKeyValueSorting) sortedArrayUsingDescriptors:] + 536
19  Eikon                                0x0000000100198b98 __51-[EIKNewsHeadlineStoreManager saveHeadlines:block:]_block_invoke (EIKNewsHeadlineStoreManager.m:67)
20  CoreData                             0x0000000183e5e214 developerSubmittedBlockToNSManagedObjectContextPerform + 148
21  libdispatch.dylib                    0x000000018099a9a0 _dispatch_client_callout + 12
22  libdispatch.dylib                    0x00000001809a8ad4 _dispatch_queue_serial_drain + 924
23  libdispatch.dylib                    0x000000018099e2cc _dispatch_queue_invoke + 880
24  libdispatch.dylib                    0x00000001809a8fa8 _dispatch_queue_override_invoke + 340
25  libdispatch.dylib                    0x00000001809aaa50 _dispatch_root_queue_drain + 536
26  libdispatch.dylib                    0x00000001809aa7d0 _dispatch_worker_thread3 + 120
27  libsystem_pthread.dylib              0x0000000180ba31d0 _pthread_wqthread + 1092
28  libsystem_pthread.dylib              0x0000000180ba2d7c start_wqthread + 0

我要做的是每隔5或10秒从服务器获取一些新闻标题,使用NSSortDescriptors以某种顺序对它们进行排序,然后将它们存储在我的CoreData中。这正是saveHeadlines:block方法在我的课程中正在做的事情。

objc_msgSend() selector name: length 究竟是什么意思?任何帮助表示赞赏。

注意:这是一个零星的问题。当我在模拟器或我的设备中测试它没有崩溃。但我们的应用程序的一些用户正在报告这次崩溃。

编辑问题:在saveHeadlines内部:块方法

        __weak typeof(self) weakSelf = self;
    [self.privateMOC performBlock:^{

        NSMutableArray *newsTopics = [[EIKNewsTopicStoreManager managedObjectsInManagedObjectContext:self.privateMOC] mutableCopy];
        [newsTopics addObjectsFromArray:[EIKNewsTopicStoreManager topicsManagedObjectForNewsFeedInContext:self.privateMOC]];
        weakSelf.storedHeadlines = [NSMutableSet set];

        for (NSManagedObject *storedTopic in newsTopics) {
            [weakSelf.storedHeadlines addObjectsFromArray:[[storedTopic valueForKey:EIKFeedTopicRelationshipItems] allObjects]];
        }

        NSArray *sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:EIKNewsHeadlineAttributeHeadlineId ascending:YES]];
        NSArray *orderedItems = [items sortedArrayUsingDescriptors:sortDescriptors];
        NSArray *orderedHeadlines = [weakSelf.storedHeadlines sortedArrayUsingDescriptors:sortDescriptors];

崩溃发生在最后一行。即

 NSArray *orderedHeadlines = [weakSelf.storedHeadlines sortedArrayUsingDescriptors:sortDescriptors];

无法弄清楚原因。!

我的NSManagedObjectContext初始化如此[即privateMOC,如上面的代码所示]

NSManagedObjectContext *confinementContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSPrivateQueueConcurrencyType];

1 个答案:

答案 0 :(得分:0)

此处信息不多,但我认为NSManagedObjectContext在您执行操作的主题上无效。 请确保您在上下文的专用队列中执行所有操作。您可以使用performBlock:performBlockAndWait:来执行此操作。 此外,您不能在不同的线程上重用NSManagedObject的实例,而不是您获取它们的线程。 希望有所帮助。