gpt4 book ai didi

ios - 查询没有帐户属性的 IOS Keychain?

转载 作者:行者123 更新时间:2023-11-28 14:52:05 25 4
gpt4 key购买 nike

您好,我目前正在尝试在没有 kSecAttrAccountValue 属性且仅使用 kSecAttrServiceValue 的情况下为我的项目查询钥匙串(keychain)。这可能吗?状态显示为 0,但响应为零。我尝试添加一个帐户,效果很好!但是,我的目标是获得没有它的结果或存储在同一服务中的所有结果。请告诉我谢谢!

引用: Save and Load from KeyChain | Swift

代码:

let keychainQuery: NSMutableDictionary = NSMutableDictionary(objects: [kSecClassGenericPasswordValue, service, kCFBooleanTrue, kSecMatchLimitOneValue], forKeys: [kSecClassValue, kSecAttrServiceValue, kSecReturnDataValue, kSecMatchLimitValue])

var dataTypeRef :AnyObject?

// Search for the keychain items
let status: OSStatus = SecItemCopyMatching(keychainQuery, &dataTypeRef)
var contentsOfKeychain: String?

if status == errSecSuccess {
if let retrievedData = dataTypeRef as? Data {
contentsOfKeychain = String(data: retrievedData, encoding: String.Encoding.utf8)
}
} else {
print("Nothing was retrieved from the keychain. Status code \(status)")
}

return contentsOfKeychain

最佳答案

通过 KeychainAccess 使用钥匙串(keychain)要简单得多:

// Create keychain object
let keychain = Keychain(service: "com.company.AppName")

// Store value in keychain
keychain["password"] = "test"

// Retrieve value from keychain
let password = keychain["password"]

关于ios - 查询没有帐户属性的 IOS Keychain?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49763567/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com