如果在insertNewObjectForEntityForName

时间:2016-09-20 09:21:10

标签: ios core-data

我有一个奇怪的问题,一个适用于iOS< 10。

的应用程序

将手机更新到iOS 10后,我的应用在executeFetchRequest之前insertNewObjectForEntityForName执行时崩溃。

似乎主要是iPhone6及以上有问题(已被告知iPhone5没问题)。

以下代码中的这一行正在崩溃:

NSArray *results = [context executeFetchRequest:fetchRequest error:&error];

xcode error picture 这些方法让我在Scada'类:

+(Scada *)getFirstScada {
    NSError *error = nil;
    NSArray *results = [context executeFetchRequest:fetchRequest error:&error];   //Crashing here

    Scada *retVal = nil;

    //maybe some check before, to be sure results is not empty
    if ([results count] == 0) {
        retVal = nil;
    } else {
        retVal = [results firstObject];
    }

    return retVal;
}

+ (int)insertNewScada:(NSString *)scadaName HostName:(NSString *)scadaHostName {
    int returnValue = 0;

    Scada *newScada = [NSEntityDescription insertNewObjectForEntityForName:NSStringFromClass([Scada class]) inManagedObjectContext:context];

    //Configure the new scada object.
    [newScada setName:scadaName];
    [newScada setHostname:[scadaHostName uppercaseString]];

    // Save the context.
    NSError *error = nil;
    if (![context save:&error]) {
        NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
        returnValue = -1;
    } else {
        returnValue = 1;
    }

    return returnValue;
}

今天我的电话就像AppDelegate

一样

不能工作:

Scada *scada = [Scada getFirstScada];

使用:

[Scada insertNewScada:@"tmp" HostName:@"T.E.M.P/DELETE"];
[Scada removeScada:@"T.E.M.P/DELETE"];

Scada *scada = [Scada getFirstScada];

崩溃日志(不是全部):

  

Crashed Thread:0 Dispatch queue:com.apple.main-thread

     

异常类型:EXC_BAD_ACCESS(SIGSEGV)异常代码:
  EXC_I386_GPFLT异常注意:EXC_CORPSE_NOTIFY

     

特定于应用程序的信息:objc_msgSend()选择器名称:   fetchLimit CoreSimulator 303.8 - 设备:iPhone 6s - 运行时:iOS 10.0   (14A345) - DeviceType:iPhone 6s

     

Thread 0 Crashed :: Dispatch queue:com.apple.main-thread 0
  libobjc.A.dylib 0x000000010e19facb objc_msgSend + 11 1   com.novotek.SmartDirect 0x000000010b1d113a + [Scada   getFirstScada] + 74(Scada.m:120)2 com.novotek.SmartDirect
    0x000000010b1f21fd - [AppDelegate   application:didFinishLaunchingWithOptions:] + 109(AppDelegate.m:36)3   com.apple.UIKit 0x000000010c3f968e - [UIApplication   _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 290 4 com.apple.UIKit 0x000000010c3fb013 - [UIApplication   _callInitializationDelegatesForMainScene:transitionContext:] + 4236 5 com.apple.UIKit 0x000000010c4013b9 - [UIApplication   _runWithMainScene:transitionContext:completion:] + 1731 6 com.apple.UIKit 0x000000010c3fe539 - [UIApplication   workspaceDidEndTransaction:] + 188 7 com.apple.FrontBoardServices     0x000000010feef76b FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK + 24   8 com.apple.FrontBoardServices 0x000000010feef5e4 - [FBSSerialQueue   _performNext] + 189 9 com.apple.FrontBoardServices 0x000000010feef96d - [FBSSerialQueue _performNextFromRunLoopSource] +   45 10 com.apple.CoreFoundation 0x000000010e6cd311    CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 17 11 com.apple.CoreFoundation 0x000000010e6b259c   __CFRunLoopDoSources0 + 556 12 com.apple.CoreFoundation 0x000000010e6b1a86 __CFRunLoopRun + 918 13 com.apple.CoreFoundation     0x000000010e6b1494 CFRunLoopRunSpecific + 420 14 com.apple.UIKit
    0x000000010c3fcdb6 - [UIApplication _run] + 434 15 com.apple.UIKit
    0x000000010c402f34 UIApplicationMain + 159 16   com.novotek.SmartDirect 0x000000010b1e6d7f main + 111   (main.m:16)17 libdyld.dylib 0x000000010f55b68d   开始+ 1

     

线程1:0 libsystem_kernel.dylib 0x000000010f8875e2   __workq_kernreturn + 10 1 libsystem_pthread.dylib 0x000000010f99b578 _pthread_wqthread + 1283 2
  libsystem_pthread.dylib 0x000000010f999341 start_wqthread + 13

     

线程2 ::调度队列:com.apple.libdispatch-manager 0
  libsystem_kernel.dylib 0x000000010f887efa kevent_qos + 10 1
  libdispatch.dylib 0x000000010f506c3b   _dispatch_mgr_wait_for_event + 79 2 libdispatch.dylib 0x000000010f500a85 _dispatch_mgr_invoke + 248 3 libdispatch.dylib
    0x000000010f500887 _dispatch_mgr_thread + 54

     

线程3:0 libsystem_pthread.dylib 0x000000010f999334   start_wqthread + 0

     

线程4:0 libsystem_kernel.dylib 0x000000010f8875e2   __workq_kernreturn + 10 1 libsystem_pthread.dylib 0x000000010f99b578 _pthread_wqthread + 1283 2
  libsystem_pthread.dylib 0x000000010f999341 start_wqthread + 13

     

线程5 :: com.apple.uikit.eventfetch-thread 0
  libsystem_kernel.dylib 0x000000010f880f72 mach_msg_trap + 10 1   libsystem_kernel.dylib 0x000000010f8803b3 mach_msg + 55 2
  com.apple.CoreFoundation 0x000000010e6b27b4    CFRunLoopServiceMachPort + 212 3 com.apple.CoreFoundation 0x000000010e6b1c31 __CFRunLoopRun + 1345 4 com.apple.CoreFoundation     0x000000010e6b1494 CFRunLoopRunSpecific + 420 5
  com.apple.Foundation 0x000000010dc6c080    - [NSRunLoop(NSRunLoop)runMode:beforeDate:] + 274 6 com.apple.Foundation 0x000000010dcf3a21    - [NSRunLoop(NSRunLoop)runUntilDate:] + 78 7 com.apple.UIKit 0x000000010ce8896d - [UIEventFetcher threadMain] + 118 8
  com.apple.Foundation 0x000000010dc7bf74 __NSThread__start
  + 1243 9 libsystem_pthread.dylib 0x000000010f99b99d _pthread_body + 131 10 libsystem_pthread.dylib 0x000000010f99b91a _pthread_start + 168 11 libsystem_pthread.dylib
    0x000000010f999351 thread_start + 13

     

线程0与X86线程状态(64位)崩溃:rax:   0x0000000000000000 rbx:0x0000000000000000 rcx:0x000000010dff6170   rdx:0x0000000000000004 rdi:0x00006000000cf5e0 rsi:   0x000000010c223983 rbp:0x00007fff54a2e280 rsp:0x00007fff54a2dbf8
  r8:0x0000000000000070 r9:0x00006000000cf5e0 r10:   0xbadd7088dd4fbead r11:0x000000010c223983 r12:0x00006000001ddc40   r13:0x00006000000cf5e0 r14:0x000060000005f710 r15:   0x5e0081f7ad0372c5 rip:0x000000010e19facb rfl:0x0000000000010202   cr2:0x000000010bfd9e18逻辑CPU:0错误代码:
  0x00000000陷阱号码:13

     

二进制图像:          0x10b1cf000-0x10b200ff + com.novotek.SmartDirect(2.1.0-160906)< 9C490211-3872-3C30-97F6-FDE317F5A424>   /Users/USER/Library/Developer/CoreSimulator/Devices/34113BFD-BEE2-4BEF-B77E-0A7DD14B2C55/data/Containers/Bundle/Application/34D88A3E-8915-4552-AAEC-5F4D2F415983/SmartDirect.app/SmartDirect          0x10b237000 - 0x10b25f707 + dyld_sim(360.22)   /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/usr/lib/dyld_sim          0x10b2a8000-0x10b333fff com.apple.Security(10.0-???)< 71DB299C-DADC-331C-A9D8-1DB136470E89>   /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/Frameworks/Security.framework/Security          0x10b39c000 - 0x10b746fff com.apple.audio.toolbox.AudioToolbox(1.8 - 1.8)   < 811188B5-6E3B-30E2-986E-19C52D09BC51>   /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/Frameworks/AudioToolbox.framework/AudioToolbox          0x10b8ae000 - 0x10bee1fff com.apple.CoreGraphics(2.0 - 1070)   /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/Frameworks/CoreGraphics.framework/CoreGraphics          0x10bfbe000-0x10c295ff7 + CoreData(752.1)< 38BD041F-73CC-3993-8FB5-BAE51919D9BA>   /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/Frameworks/CoreData.framework/CoreData          0x10c3db000-0x10d282ff7 com.apple.UIKit(1.0-1000)< 8E889F15-2893-3D6E-B9DB-D2C7F3EA4CDF>   /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/Frameworks/UIKit.framework/UIKit          0x10dc4b000 - 0x10df31ff3 com.apple.Foundation(6.9 - 1349)   /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/Frameworks/Foundation.framework/Foundation          0x10e184000-0x10e552eaf + libobjc.A.dylib(706)< 6726AAD7-2FA9-3AEE-AAFC-8C72CAF72E80>   /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/usr/lib/libobjc.A.dylib

1 个答案:

答案 0 :(得分:0)

感谢您的帮助。

它似乎是一个静态方法,它被调用两次,重新初始化一个变量。

在寻找崩溃日志的同时找到了解决方案,并在xcode中偶然发现了Zombie ......