OGeek|极客世界-中国程序员成长平台

标题: iOS10 Open Beta - iOS Core Data 保存时崩溃 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 11:52
标题: iOS10 Open Beta - iOS Core Data 保存时崩溃

我假设在这里发布测试版 iOS10 问题是可以的,因为它是一个公开测试版。苹果论坛在 Stackoverflow 上获得的帮助远不及。

自从更新到 iOS10 后,我们的用户在 CoreData 中保存 managedObjectContext 时经常遇到崩溃。

这是自 iOS 5 以来完美运行的东西。

它只发生在 64 位版本的 iOS10 上。 32位版本运行良好。

这是我的简单保存代码片段:

    [self.managedObjectContext performBlockAndWait:^{
    NSError *error;
    if (![self.managedObjectContext save:&error])
    {
       NSLog(@"\n\nerror in save 1 %@\n\n", error);
    }
}];

[self.managedObjectContext performBlock:^{
    NSError *error;
    if (![_privateWriterContext save:&error])
    {
       NSLog(@"\n\nerror in save 2 %@\n\n", error);
    }
}];

(上面的 NSLog 没有任何报告,因为它在模拟器中工作)。

这仅在 64 位设备上失败。我无法在模拟器上复制。由于我唯一的 64 位设备无法正确连接到 Xcode,我也无法在设备上进行调试。所以我有点卡住了。

以下是用户报告的示例堆栈跟踪:

    Incident Identifier: 7A8DD23B-48A2-4ABF-88E7-67F1E6CDA8D5
CrashReporter Key:   5454e7c7b99a94cd75b6adfa8334bbdf10b859eb
Hardware Model:      iPhone8,1
Code Type:           ARM-64 (Native)
Role:                Foreground
Parent Process:      launchd [1]



Date/Time:           2016-07-20 22:23:00.1429 -0400
Launch Time:         2016-07-20 22:21:30.6058 -0400
OS Version:          iPhone OS 10.0 (14A5309d)
Report Version:      104

Exception Type:  EXC_BAD_ACCESS (SIGSEGV)
Exception Subtype: KERN_INVALID_ADDRESS at 0x0000000985e4beb8
Triggered by Thread:  0

Thread 0 name:
Thread 0 Crashed:
0   libobjc.A.dylib                 0x00000001850e6eb0 objc_msgSend + 16
1   CoreFoundation                  0x0000000185a76740 __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 20 (CFNotificationCenter.c:650)
2   CoreFoundation                  0x0000000185a75e44 _CFXRegistrationPost + 400 (CFNotificationCenter.c:164)
3   CoreFoundation                  0x0000000185a75bc0 ___CFXNotificationPost_block_invoke + 60 (CFNotificationCenter.c:1031)
4   CoreFoundation                  0x0000000185ae40cc -[_CFXNotificationRegistrar findbjectbserver:enumerator:] + 1504 (CFXNotificationRegistrar.m:163)
5   CoreFoundation                  0x00000001859b9484 _CFXNotificationPost + 376 (CFNotificationCenter.c:1028)
6   Foundation                      0x000000018644e9dc -[NSNotificationCenter postNotificationNamebject:userInfo:] + 68 (NSNotification.m:482)
7   CoreData                        0x0000000187e1dbf4 -[NSManagedObjectContext(_NSInternalNotificationHandling) _postContextDidSaveNotificationWithUserInfo:] + 880 (NSManagedObjectContext.m:7381)
8   CoreData                        0x0000000187dabb4c -[NSManagedObjectContext(_NSInternalAdditions) _didSaveChanges] + 2156 (NSManagedObjectContext.m:5827)
9   CoreData                        0x0000000187d98570 -[NSManagedObjectContext save:] + 3440 (NSManagedObjectContext.m:1532)
10  App                             0x000000010008db34 __29-[RPSAppDelegate saveContext]_block_invoke227 + 52 (RPSAppDelegate.m:338)
11  CoreData                        0x0000000187e17c68 developerSubmittedBlockToNSManagedObjectContextPerform + 168 (NSManagedObjectContext.m:3529)
12  libdispatch.dylib               0x0000000185525784 _dispatch_client_callout + 16 (object.m:455)
13  libdispatch.dylib               0x000000018552a330 _dispatch_main_queue_callback_4CF + 1000 (inline_internal.h:2421)
14  CoreFoundation                  0x0000000185a8a0cc __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 12 (CFRunLoop.c:1793)
15  CoreFoundation                  0x0000000185a87cb8 __CFRunLoopRun + 1660 (CFRunLoop.c:3004)
16  CoreFoundation                  0x00000001859b78d8 CFRunLoopRunSpecific + 444 (CFRunLoop.c:3113)
17  GraphicsServices                0x00000001873be198 GSEventRunModal + 180 (GSEvent.c:2245)
18  UIKit                           0x000000018b9617c8 -[UIApplication _run] + 664 (UIApplication.m:2651)
19  UIKit                           0x000000018b95c534 UIApplicationMain + 208 (UIApplication.m:4088)
20  App                             0x000000010008c138 main + 152 (main.m:27)
21  libdyld.dylib                   0x00000001855585b8 start + 4

感谢您的任何想法。



Best Answer-推荐答案


您将 _privateWriterContext 保存在 managedObjectContext 的 block 调用中。这是不允许的。它之前有效的事实是“误报”。

相反,您应该始终只在创建 block 的同一上下文中使用。

关于iOS10 Open Beta - iOS Core Data 保存时崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38806916/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4