Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I know this is from several months ago, but I just had the same problem and it was painful so I thought I'd share. I solved it by adding this line:</p> <pre><code>[self.keychainItemWrapper setObject:@"MY_APP_CREDENTIALS" forKey:(id)kSecAttrService]; //@"MY_APP_CREDENTIALS" can be any string. </code></pre> <p>I found this blog entry very helpful: "In database terms you could think of their being a unique index on the two attributes kSecAttrAccount, kSecAttrService requiring the combination of those two attributes to be unique for each entry in the keychain." (from <a href="http://useyourloaf.com/blog/2010/4/28/keychain-duplicate-item-when-adding-password.html" rel="noreferrer">http://useyourloaf.com/blog/2010/4/28/keychain-duplicate-item-when-adding-password.html</a>).</p> <p>Also, in Apple's example project using this code, they instantiate KeychainItemWrapper in the app delegate. I don't know if it's necessary, but I like to follow their examples as closely as possible:</p> <pre><code>- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{ //there will be some standard code here. KeychainItemWrapper *wrapper = [[KeychainItemWrapper alloc] initWithIdentifier:@"MY_APP_CREDENTIALS" accessGroup:nil]; self.keychainWrapper = wrapper; [self.keychainWrapper setObject:@"MYOBJECT" forKey:(id)kSecAttrService]; [wrapper release]; } </code></pre> <p>I think this is a bug in the wrapper code. The logic basically says "Does this entry exist already? No, it doesn't. OK, I'll add it. Oops, you can't add it because it's already there."</p> <p>You may also need to set kSecAttrAccount; I've never tried it without also setting this value since it's intended to save the username that goes with the password:</p> <pre><code>[self.wrapper setObject:txtUserName.text forKey:(id)kSecAttrAccount]; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload