我想仅使用 PassCode
进行身份验证,即使设备具有 Touch ID
功能。我正在使用 .deviceOwnerAuthentication
评估策略方法。当我使用它时,
- If user has enrolled touch id --> alway ask for touch id
- If use hasn't enrolled touch id --> then only ask for passcode
我想要的是,即使用户已经注册了 touch id
,只需要 passcode
。希望您对此有所帮助。
这可以通过将 SecAccessControlCreateFlags
设置为 .devicePasscode
使用安全框架使用 SecAccessControl
来完成。
添加钥匙串(keychain)项,
let secAccessControlbject: SecAccessControl = SecAccessControlCreateWithFlags(kCFAllocatorDefault,
kSecAttrAccessibleWhenUnlockedThisDeviceOnly,
.devicePasscode,
nil)!
let dataToStore = "AnyData".data(using: .utf8)!
let insertQuery: NSDictionary = [
kSecClass: kSecClassGenericPassword,
kSecAttrAccessControl: secAccessControlbject,
kSecAttrService: "asscodeAuthentication",
kSecValueData: dataToStore as Any,
]
let insertStatus = SecItemAdd(insertQuery as CFDictionary, nil)
要通过密码屏幕进行身份验证,请访问已保存的项目,
let query: NSDictionary = [
kSecClass: kSecClassGenericPassword,
kSecAttrService : "asscodeAuthentication",
kSecUseOperationPrompt : "Sign in"
]
var typeRef : CFTypeRef?
let status: OSStatus = SecItemCopyMatching(query, &typeRef) //This will prompt the passcode.
if (status == errSecSuccess)
{
print("Authentication Success")
}
关于ios - 是否可以仅使用密码进行身份验证,即使设备在 ios 中具有 touch id 功能,swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46723662/
欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://jike.in/) | Powered by Discuz! X3.4 |