SecItemCopyMatching (crash)

I found a crash by chance. It doesn't come up often. I upload the crash log. it seems the SecItemCopyMatching crashes. but I don not find the reason.


    static LMNetwork * aInstance = nil;

    static dispatch_once_t onceToken;

    dispatch_once(&onceToken, ^{

        aInstance = [[LMNetwork alloc] init];


        [aInstance checkNetWorkStatus];



    return aInstance;


- (instancetype)init{

  if (self = [super init]){ 

    self.networkQueue = dispatch_queue_create("", DISPATCH_QUEUE_CONCURRENT);

    self.backQueueManager.completionQueue = self.networkQueue;

    self.ioQueue = dispatch_queue_create("", DISPATCH_QUEUE_CONCURRENT);

      dispatch_sync(self.ioQueue, ^{

          NSString* countryCode = [LMKeyChain objectForKey:@"loginCountryCode"];

          [LMKeyChain removeObjectForKey:@"loginCountryCode"];


+ (NSString*)objectForKey:(NSString*)key


 NSMutableDictionary *keychainQuery = [NSMutableDictionary dictionaryWithObjectsAndKeys:

                                              (__bridge id)kSecClassGenericPassword,(__bridge id)kSecClass,

                                              key, (__bridge id)kSecAttrService,

                                              key, (__bridge id)kSecAttrAccount,

                                              (__bridge id)kSecAttrAccessibleAfterFirstUnlock,(__bridge id)kSecAttrAccessible,


        [keychainQuery setObject:(__bridge id)kCFBooleanTrue forKey:(__bridge id)kSecReturnData];

        [keychainQuery setObject:(__bridge id)kSecMatchLimitOne forKey:(__bridge id)kSecMatchLimit];

        CFDataRef keyData = NULL;

        if (SecItemCopyMatching((__bridge CFDictionaryRef)keychainQuery, (CFTypeRef *)&keyData) == noErr) {

            @try {

                ret = [NSKeyedUnarchiver unarchiveObjectWithData:(__bridge NSData *)keyData];

            } @catch (NSException *e) {

                NSLog(@"Keychain Unarchive of %@ failed: %@", key, e);


 if (keyData != NULL) {
    ret = [NSKeyedUnarchiver unarchiveObjectWithData:(__bridge NSData *)keyData];
SecItemCopyMatching (crash)