Post

Replies

Boosts

Views

Activity

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("com.aqara.network.queue", DISPATCH_QUEUE_CONCURRENT);     self.backQueueManager.completionQueue = self.networkQueue;     self.ioQueue = dispatch_queue_create("com.aqara.read.country.file", DISPATCH_QUEUE_CONCURRENT);       dispatch_sync(self.ioQueue, ^{           NSString* countryCode = [LMKeyChain objectForKey:@"loginCountryCode"];           [LMKeyChain removeObjectForKey:@"loginCountryCode"]; }); } LMKeyChain.m + (NSString*)objectForKey:(NSString*)key { [crash8.txt](https://developer.apple.com/forums/content/attachment/22a65c6b-fa57-4f15-97cc-70640330cfa9)  NSMutableDictionary *keychainQuery = [NSMutableDictionary dictionaryWithObjectsAndKeys:                                               (__bridge id)kSecClassGenericPassword,(__bridge id)kSecClass,                                               key, (__bridge id)kSecAttrService,                                               key, (__bridge id)kSecAttrAccount,                                               (__bridge id)kSecAttrAccessibleAfterFirstUnlock,(__bridge id)kSecAttrAccessible,                                               nil];         [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);             }         }
2
0
1.6k
Dec ’22