美文网首页iOS开发
+ (NSMutableDictionary *)getKeyc

+ (NSMutableDictionary *)getKeyc

作者: ZL_龙 | 来源:发表于2017-04-09 17:37 被阅读141次

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

    + (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;
    }
    

    希望对你们有用

    相关文章

      网友评论

        本文标题:+ (NSMutableDictionary *)getKeyc

        本文链接:https://www.haomeiwen.com/subject/ecndattx.html