这是我的代码:
static void SetA(byte[] b)
{
var result = SecKeyChain.Add(new SecRecord(SecKind.Key) { Generic = "test", ValueData = NSData.FromArray(b) });
Debug.WriteLine(result);
}
结果
是:
NoSuchAttribute
- 是因为我正在调试并且当我发布它时它会起作用吗?
- 是因为我需要向 info.plist 添加一些内容吗?
- 是因为我需要在配置中指定一些内容吗 个人资料?
- 或者是因为我遗漏了代码中的某些步骤?
- ...
这是我第一次尝试使用 KeyChain,因此请不要低估(如“忽略”)我可能犯的任何简单错误。
最佳答案
我遇到了完全相同的错误。我正在关注这里的官方样本 https://github.com/xamarin/ios-samples/tree/master/Keychain .
我调试了一下,发现错误NoSuchAttribute
来自Generic
属性。在 official Apple documentation kSecAttrGeneric属性列在“密码属性”下。所以我假设 xamarin 示例是正确的,因为它使用 SecKind.GenericPassword
.
替换Generic
通过Label
或其他东西来识别您的钥匙串(keychain)记录。
使用您的代码
static void SetA(byte[] b)
{
var result = SecKeyChain.Add(new SecRecord(SecKind.Key) {
Label = "test",
ValueData = NSData.FromArray(b)
});
Debug.WriteLine(result);
}
关于ios - 钥匙串(keychain)集 - NoSuchAttribute - 为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58221460/