[英]Correct way to remove(purge) all keychain data for an iOS app
我在钥匙串中存储了一些信息,有一种情况我需要删除所有项目,而不是为所有密钥执行[keychain removeObjectForKey:theKey]
,我可以这样做:
NSDictionary *spec = [NSDictionary dictionaryWithObjectsAndKeys:(id)kSecClassGenericPassword, kSecClass,
[self serviceName], kSecAttrService, nil];
return !SecItemDelete((CFDictionaryRef)spec);
代替?
我尝试了它并且它有效,只是不确定我是否正在做正确的事情?
在我的应用程序中,我正在使用此行来清除我的钥匙串:
[[[KeychainItemWrapper alloc] initWithIdentifier:@"my_key" accessGroup:nil] resetKeychainItem]
我相信你所做的是正确的,事实上,你可以根据需要避免查询中的kSecAttrService参数。 另一方面,SecItemDelete返回OSStatus值,您可以检查该事务的更多详细信息。
NSDictionary *spec = [NSDictionary dictionaryWithObjectsAndKeys:(id)kSecClassGenericPassword, kSecClass, nil];
OSStatus status = SecItemDelete((CFDictionaryRef)spec);
if (status == errSecSuccess)
return YES;
return NO;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.