iOS开发

+ (NSMutableDictionary *)getKeyc

2017-04-09  本文已影响141人  ZL_龙

这几天检查程序的泄露问题发现获取手机标识的方法存在内存泄露,查看问题出在 下面的方法

+ (NSMutableDictionary *)getKeychainQuery:(NSString *)service {
    return [NSMutableDictionary dictionaryWithObjectsAndKeys:
           (__bridge id)kSecClassGenericPassword,(__bridge id)kSecClass,
            service, (__bridge id)kSecAttrService,
            service, (__bridge id)kSecAttrAccount,
            (__bridge id)kSecAttrAccessibleAfterFirstUnlock,(__bridge id)kSecAttrAccessible,
            nil];
} 

google很久也有发生类似问题的朋友解决方法如下:

+ (NSMutableDictionary *)getKeychainQuery:(NSString *)service {
    return [NSMutableDictionary dictionaryWithObjectsAndKeys:
                   (__bridge_transfer id)kSecClassGenericPassword,(__bridge_transfer id)kSecClass,
                   service, (__bridge_transfer id)kSecAttrService,
                   service, (__bridge_transfer id)kSecAttrAccount,
                   (__bridge_transfer id)kSecAttrAccessibleAfterFirstUnlock,(__bridge_transfer id)kSecAttrAccessible,
                   nil];
} 

然儿我这里改过后发现依然不好使这个怎么办那~~~~~最后自己摸索用下面的方法就可以,分享给大家:

static NSMutableDictionary * queryDIC;
+ (NSMutableDictionary *)getKeychainQuery:(NSString *)service {
   
    if (!queryDIC) {
        queryDIC =[NSMutableDictionary dictionaryWithObjectsAndKeys:
                   (__bridge_transfer id)kSecClassGenericPassword,(__bridge_transfer id)kSecClass,
                   service, (__bridge_transfer id)kSecAttrService,
                   service, (__bridge_transfer id)kSecAttrAccount,
                   (__bridge_transfer id)kSecAttrAccessibleAfterFirstUnlock,(__bridge_transfer id)kSecAttrAccessible,
                   nil];
    }
    return queryDIC;
}

希望对你们有用

上一篇下一篇

猜你喜欢

热点阅读