title: Keychain access in iOS: "Keychain failed to store the value with code: -50"
body: <p>I don't find the information regarding such error code when calling <code>SecItemAdd</code>, what could be causing it?</p>
  
  <p>Thanks in advance</p>
  
  <p><strong>EDIT:</strong> This is the function where I get the error:</p>
  
  <pre><code>+ (BOOL)storeWithKey:(NSString *)keyStr withValueStr:(NSString *)valueStr
  {
     if ((keyStr != nil) &amp;&amp; (![keyStr isEqualToString:@""]) &amp;&amp;
         (valueStr != nil) &amp;&amp; (![valueStr isEqualToString:@""])) {
  
         NSData *valueData = [valueStr dataUsingEncoding:NSUTF8StringEncoding];
         NSString *service = [[NSBundle mainBundle] bundleIdentifier];
  
         NSDictionary *secItem = @{(__bridge id)kSecClass : (__bridge id)kSecClassInternetPassword,
                                (__bridge id)kSecAttrService : service,
                                (__bridge id)kSecAttrAccount : keyStr,
                                (__bridge id)kSecValueData : valueData};
  
         CFTypeRef result = NULL;
  
         // Store value and get the result code
         OSStatus status = SecItemAdd((__bridge CFDictionaryRef)secItem, &amp;result);
  
         NSLog(@"'writeToKeychain'. %@", [self getErrorMessage:status]);
  
         return [self checkIfInKeychain:status];
     }
     else {
         return NO;
     }
  }
  </code></pre>