SecItemAdd returning OSStatus code

I am trying to write to the keychain in iOS and whenever I try to write to the keychain while testing on my device, I am getting the -50 error code as the result of SecItemAdd.

I first tried to implement such a mechanism myself, and after getting the error lots of times, I tried KeychainItemWrapper, thinking that I was doing something wrong. But using KeychainItemWrapper also gives me the same error code: (ARCified version of KeychainItemWrapper, https://gist.github.com/dhoerl/1170641)

line 305: NSAssert( result == noErr, @"Couldn't add the Keychain Item." );

Result is -50, the same result that I've been getting when I was trying it myself. Here is how I'm using the wrapper (with access group being my app id)

keychain = [[KeychainItemWrapper alloc] initWithIdentifier:@"data" accessGroup:@"my.app.identifier"];
purchasedPacks = [keychain objectForKey:@"packs"];
if(purchasedPacks == nil){
    [keychain setObject:[[NSMutableArray alloc] init] forKey:@"packs"];
}

I've first thought that maybe setting a mutable array would be a problem, but trying a string also failed the same way. What could be the cause of the problem?

Thanks, Can.


You cannot use arbitrary keys for [keychain setObject: forKey:] . The following will work:

[keychain setObject:[[NSMutableArray alloc] init]
          forKey:(__bridge id)kSecValueData]

The Apple documentation is full of information regarding this.

链接地址: http://www.djcxy.com/p/14600.html

上一篇: 如何判断一个DOM元素在当前视口中是否可见?

下一篇: SecItemAdd返回OSStatus代码