ios - Swift:注销后无法再次登录钥匙串
问题描述
这是使用 KeychainService 的正确方法吗?
我第一次登录没有问题,但是在我注销并尝试再次登录后。状态返回 403 禁止。如何删除会话 ID?
public class KeychainService: NSObject {
class func savePassword(service: String, account: String, data: String) {
if let dataFromString = data.data(using: String.Encoding.utf8, allowLossyConversion: false) {
let keychainQuery: NSMutableDictionary = NSMutableDictionary(objects: [kSecClassGenericPasswordValue, service, account, dataFromString], forKeys: [kSecClassValue, kSecAttrServiceValue, kSecAttrAccountValue, kSecValueDataValue])
let status = SecItemAdd(keychainQuery as CFDictionary, nil)
if (status != errSecSuccess) {
}
print("success")
}
}
class func removePassword(service: String, account: String) {
let keychainQuery: NSMutableDictionary = NSMutableDictionary(objects: [kSecClassGenericPasswordValue, service, account, kCFBooleanTrue, kSecMatchLimitOneValue], forKeys: [kSecClassValue, kSecAttrServiceValue, kSecAttrAccountValue, kSecReturnDataValue, kSecMatchLimitValue])
var dataTypeRef: AnyObject?
let status: OSStatus = SecItemCopyMatching(keychainQuery, &dataTypeRef)
if status == errSecSuccess {
let statusDelete = SecItemDelete(keychainQuery as CFDictionary)
if (statusDelete != errSecSuccess) {
}
} else {
print("failed")
}
}
}
解决方案
推荐阅读
- php - 如何在 PHPUnit 中模拟带注释的 AWS 方法?
- c# - 如何在使用 Unity Scriptable API 的脚本中使用 Humanoid Model : Animator(property)
- java - 为什么我的秒表程序无法运行?
- arrays - 将字节数组转换为 int64 golang 数组
- r - 创建 ggplot2 stat 扩展的计算错误
- python - 使用 pandas 从 json 文件中提取数据时,布尔值会自动转换为大写
- c# - C# 中是否有任何方法,例如 Java 中的 equalsIgnoreCase
- google-cloud-platform - GCP IoTCore won't parse payload using Gateways and HTTP bridge
- innerhtml - 如何使用 innerHTML 将 js 数组插入到 html 中?
- ruby-on-rails - 如何将查询参数放在 _path rails_helper 上