有没有办法确定是否已使用Touch ID访问控制在iOS钥匙串中设置了项目(密码,令牌等)而没有提示用户输入Touch ID?在执行操作之前,我们需要确定凭证是否已保存到钥匙串(带有Touch ID保护),但我们不希望使用Touch ID提示中断用户.
我试过以下......
NSMutableDictionary *query = ... query[(__bridge id)kSecUseNoAuthenticationUI] = (__bridge id)kCFBooleanTrue; OSStatus opStatus = SecItemCopyMatching((__bridge CFDictionaryRef)query, NULL); ...
但是,当调用此代码时,用户仍会看到Touch ID提示.我们不希望任何东西在UI上进行显示,而只是想在返回一个错误OSStatus
,如果触摸ID 会被需要.
有什么想法吗?
基于neoneye的代码和Swift 3.我添加了errSecAuthFailed.
query[kSecClass as String] : kSecClassGenericPassword, query[kSecAttrService as String] : "serviceName" query[kSecUseAuthenticationUI as String] = kSecUseAuthenticationUIFail DispatchQueue.global().async { var result : AnyObject? let status = SecItemCopyMatching(query as CFDictionary, &result) if status == errSecInteractionNotAllowed { DispatchQueue.main.async { // item exists } } else if status == errSecAuthFailed { DispatchQueue.main.async { // item exists but someone removed the touch id or passcode } } else if status == errSecItemNotFound { DispatchQueue.main.async { // it does not exist } } else { DispatchQueue.main.async { // another OSStatus } } }
NSDictionary *query = @{ (__bridge id)kSecClass: (__bridge id)kSecClassGenericPassword, (__bridge id)kSecAttrService: @"SampleService", (__bridge id)kSecUseNoAuthenticationUI: @YES }; dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ CFTypeRef dataTypeRef = NULL; OSStatus status = SecItemCopyMatching((__bridge CFDictionaryRef)(query), &dataTypeRef); if (status == errSecInteractionNotAllowed) { NSLog(@"ITEM EXIST"); } else if (status == errSecItemNotFound) { NSLog(@"ITEM DOES NOT EXIST"); } else { NSLog(@"status: %@", @(status)); } });