MonoTouch SecKeyChain.Add返回SecStatusCode.Param

Cal*_*her 5 xamarin.ios ios

我正试图保存这样的记录:

var testRecord = new SecRecord(SecKind.GenericPassword)
{
    CreationDate = DateTime.UtcNow,
    MatchCaseInsensitive = false,
    Service = "MyService",
    Label = "MyService",
    Account = "User",
    Generic = NSData.FromString("test", NSStringEncoding.UTF8),
};
SecKeyChain.Add(testRecord);
Run Code Online (Sandbox Code Playgroud)

...但是当我在模拟器中运行它时,我得到了SecStatusCode.Param.根据文档,该代码表示​​"通过的参数无效或不完整",但我没有看到任何遗漏或异常,其他人没有取得明显的成功.

甚至向SecRecord 添加CreationDate,Invisible,Description,Comment,Accessible ValueData属性(如本示例中的一些)也没有帮助 - 仍然获得SecStatusCode.Param.

是否存在可能导致Param状态代码返回的非显而易见的事情?

val*_*ero 10

我在尝试使用钥匙串时遇到了很多麻烦.我终于让我的工作在应用程序中存储用户凭据.这是我有的:

        SecRecord existingRec = new SecRecord (SecKind.GenericPassword) { 
            Service = Keychain.USER_SERVICE, 
            Label = Keychain.USER_LABEL 
        };

        var record = new SecRecord (SecKind.GenericPassword) {
            Service = Keychain.USER_SERVICE, 
            Label = Keychain.USER_LABEL, 
            Account = username,
            ValueData = NSData.FromString (password),
            Accessible = SecAccessible.Always
        };

        SecStatusCode code = SecKeyChain.Add (record);
        if (code == SecStatusCode.DuplicateItem) {
            code = SecKeyChain.Remove (existingRec);
            if (code == SecStatusCode.Success)
                code = SecKeyChain.Add (record);
        }
Run Code Online (Sandbox Code Playgroud)

Keychain是一个带常量的静态类,所以我不必重新键入字符串.

你和我之间唯一不同的是CreationDate/ MatchCaseInsensitivedata和NSData的编码.也许尝试没有那些,看看它是否有效?如果是这样,请单独添加它们,看看是什么产生了问题.