ios - KeyChain Set - NoSuchAttribute - 为什么?
问题描述
这是我的代码:
static void SetA(byte[] b)
{
var result = SecKeyChain.Add(new SecRecord(SecKind.Key) { Generic = "test", ValueData = NSData.FromArray(b) });
Debug.WriteLine(result);
}
result
是:
NoSuchAttribute
- 是因为我正在调试并且当我发布它时它会起作用吗?
- 是因为我需要向 info.plist 添加一些内容吗?
- 是因为我需要在配置文件中指定一些东西吗?
- 还是因为我在代码中遗漏了一些步骤?
- ...
这是我第一次尝试使用 KeyChain,所以请不要忽视(如“无视”)我可能犯的任何简单错误。
解决方案
我遇到了完全相同的错误。我正在关注这里的官方示例 https://github.com/xamarin/ios-samples/tree/master/Keychain。
我调试了一下,发现ErrorNoSuchAttribute
来自Generic
属性。在Apple 官方文档中,kSecAttrGeneric属性列在“密码属性”下。所以我假设 xamarin 示例是正确的,因为它使用SecKind.GenericPassword
.
替换Generic
为Label
或其他内容以识别您的钥匙串记录。
使用您的代码
static void SetA(byte[] b)
{
var result = SecKeyChain.Add(new SecRecord(SecKind.Key) {
Label = "test",
ValueData = NSData.FromArray(b)
});
Debug.WriteLine(result);
}
推荐阅读
- python - python cassandra 在生成器中获得 select * 的大结果(在 ram 中没有存储结果)
- laravel - 两个具有相同 OneSignal 应用 ID + Laravel 服务器的 Ionic 3 应用
- r - R 语言:在 SQL 语句中使用 UDF
- sql - PostgreSQL 查询基于字符串进行拆分并将它们连接到新的单独列中
- ios - tableView 在其父视图居中时不会出现
- php - 在 Woocommerce 中隐藏特定用户角色的特定运输方式
- oracle - Oracle SQL Developer 是否与 sqlnet.ora 一起使用?
- excel - 运行时错误 1004 - 复制所选工作表失败
- python - Pandas - 列标题到行值
- c# - 在 timer_tick 期间更新文本框