0

iOSのキーチェーンに本当に問題があります。

ここにありself.keychainItemQueryます:

{
    kSecClass = kSecClassGenericPassword;
    kSecAttrGeneric = "com.mycompany.player";
    kSecMatchLimit = kSecMatchLimitOne;
    kSecReturnAttributes = kCFBooleanTrue;
}

私がする時

OSStatus status = SecItemCopyMatching((__bridge CFDictionaryRef)self.keychainItemQuery, &attributes);

私は得る

status == errSecItemNotFound

さて、ここにありself.keychainItemDataます:

{
    kSecAttrAccount = "";
    kSecClass = kSecClassGenericPassword;
    kSecAttrDescription = "";
    kSecAttrGeneric = "com.mycompany.player";
    kSecAttrLabel = "";
    kSecValueData = <35663636 65623135 64303139 65363535>;
}

しかし、私がするとき

OSStatus result = SecItemAdd((__bridge CFDictionaryRef)dictionary, NULL);

私は得る

result == errSecDuplicateItem

キーホルダーのアイテムはキーオフされていると思いましたkSecAttrGeneric。上記のクエリは、コード内の他のポイントでキーチェーンアイテムを見つけます。なぜこれが機能しないのかについての詳細が欠けているような気がします。

4

1 に答える 1

2

このブログ投稿はあなたの問題について話します。

kSecAttrAccountつまり、キーとの値も設定する必要がありますkSecAttrServicekSecClassGenericPasswordこれらの2つの値から、キーチェーンエントリの一意性を明らかに決定します。

の値を再利用できますkSecAttrGenerickSecAttrService、各キーチェーンエントリには一意のkSecAttrAccount値が必要です。

例を更新すると、次のようにself.keychainItemQueryなります。

{
    kSecClass = kSecClassGenericPassword;
    kSecAttrGeneric = "com.mycompany.player";
    kSecAttrAccount = "account";               // This value should be unique for each entry you add
    kSecAttrService = "com.mycompany.player";
    kSecMatchLimit = kSecMatchLimitOne;
    kSecReturnAttributes = kCFBooleanTrue;
}

そして次のようにself.keychainItemDataなります:

{
    kSecAttrAccount = "";
    kSecClass = kSecClassGenericPassword;
    kSecAttrDescription = "";
    kSecAttrGeneric = "com.mycompany.player";
    kSecAttrAccount = "account";               // This value should be unique for each entry you add
    kSecAttrService = "com.mycompany.player";
    kSecAttrLabel = "";
    kSecValueData = <35663636 65623135 64303139 65363535>;
}
于 2013-03-20T15:30:24.547 に答える