19 lines · 716 B · Swift
RawDownload
import Foundation #if os(macOS)import LocalAuthenticationimport Security enum KeychainNoUIQuery {    static func apply(to query: inout [String: Any]) {        let context = LAContext()        context.interactionNotAllowed = true        query[kSecUseAuthenticationContext as String] = context         // NOTE: While Apple recommends using LAContext.interactionNotAllowed, that alone is not sufficient to        // prevent the legacy keychain "Allow/Deny" prompt on some configurations. We also set the UI policy to fail        // so SecItemCopyMatching returns errSecInteractionNotAllowed instead of showing UI.        query[kSecUseAuthenticationUI as String] = kSecUseAuthenticationUIFail    }}#endif