1. <small id='ssSwq'></small><noframes id='ssSwq'>

        <tfoot id='ssSwq'></tfoot>

      2. <legend id='ssSwq'><style id='ssSwq'><dir id='ssSwq'><q id='ssSwq'></q></dir></style></legend>
          <bdo id='ssSwq'></bdo><ul id='ssSwq'></ul>

      3. <i id='ssSwq'><tr id='ssSwq'><dt id='ssSwq'><q id='ssSwq'><span id='ssSwq'><b id='ssSwq'><form id='ssSwq'><ins id='ssSwq'></ins><ul id='ssSwq'></ul><sub id='ssSwq'></sub></form><legend id='ssSwq'></legend><bdo id='ssSwq'><pre id='ssSwq'><center id='ssSwq'></center></pre></bdo></b><th id='ssSwq'></th></span></q></dt></tr></i><div id='ssSwq'><tfoot id='ssSwq'></tfoot><dl id='ssSwq'><fieldset id='ssSwq'></fieldset></dl></div>

        使用 iphone sdk 在钥匙串中保存时出错

        Error saving in the keychain with iphone sdk(使用 iphone sdk 在钥匙串中保存时出错)

          <bdo id='baAB2'></bdo><ul id='baAB2'></ul>
          <legend id='baAB2'><style id='baAB2'><dir id='baAB2'><q id='baAB2'></q></dir></style></legend>

            • <small id='baAB2'></small><noframes id='baAB2'>

            • <i id='baAB2'><tr id='baAB2'><dt id='baAB2'><q id='baAB2'><span id='baAB2'><b id='baAB2'><form id='baAB2'><ins id='baAB2'></ins><ul id='baAB2'></ul><sub id='baAB2'></sub></form><legend id='baAB2'></legend><bdo id='baAB2'><pre id='baAB2'><center id='baAB2'></center></pre></bdo></b><th id='baAB2'></th></span></q></dt></tr></i><div id='baAB2'><tfoot id='baAB2'></tfoot><dl id='baAB2'><fieldset id='baAB2'></fieldset></dl></div>

                  <tbody id='baAB2'></tbody>
                <tfoot id='baAB2'></tfoot>
                  本文介绍了使用 iphone sdk 在钥匙串中保存时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我为钥匙串使用 Apple 包装器,并尝试在其上保存一个项目(在模拟器中运行,ios 4.1).

                  I use the Apple wraper for the keychain, and try to save a item on it (running in simulator, ios 4.1).

                  我以前没有使用过钥匙串.

                  I have not experience with the keychain before.

                  我收到此错误:

                  无法添加钥匙串项.错误 - 25299

                  Couldn't add the Keychain Item. Error - 25299

                  在 KeychainItemWrapper.m 第 304 行:

                  In KeychainItemWrapper.m line 304:

                  // No previous item found; add the new one.
                  result = SecItemAdd((CFDictionaryRef)[self dictionaryToSecItemFormat:keychainItemData], NULL);
                  NSAssert( result == noErr, @"Couldn't add the Keychain Item." );
                  

                  我就是这样保存的:

                  - (void) saveKey:(NSString *)key value:(NSString *)value {
                      KeychainItemWrapper *keyItem = [[KeychainItemWrapper alloc] initWithIdentifier:key accessGroup:nil];
                      [keyItem setObject:value forKey:(id)kSecValueData];
                      [keyItem release];
                  }
                  

                  这是 api 尝试保存的值:

                  And this are the values that the api try to save:

                  <CFBasicHash 0x7231f60 [0x320d380]>{type = mutable dict, count = 5,
                  entries =>
                  2 : <CFString 0x2e6eb98 [0x320d380]>{contents = "labl"} = <CFString 0x2fb018 [0x320d380]>{contents = ""}
                  3 : <CFString 0x2e6efb8 [0x320d380]>{contents = "v_Data"} = <CFString 0x727de60 [0x320d380]>{contents = "dit8"}
                  4 : <CFString 0x2e6ebc8 [0x320d380]>{contents = "acct"} = <CFString 0x2fb018 [0x320d380]>{contents = ""}
                  5 : <CFString 0x2e6eb58 [0x320d380]>{contents = "desc"} = <CFString 0x2fb018 [0x320d380]>{contents = ""}
                  6 : <CFString 0x2e6ebe8 [0x320d380]>{contents = "gena"} = <CFString 0x2ffd08 [0x320d380]>{contents = "userCode"}
                  }
                  

                  推荐答案

                  我知道这是几个月前的事情,但我也遇到了同样的问题,而且很痛苦,所以我想我会分享.我通过添加这一行来解决它:

                  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:

                  [self.keychainItemWrapper setObject:@"MY_APP_CREDENTIALS" forKey:(id)kSecAttrService];
                  //@"MY_APP_CREDENTIALS" can be any string.
                  

                  我发现这篇博文很有帮助:在数据库术语中,您可以认为它们是 kSecAttrAccount、kSecAttrService 两个属性的唯一索引,要求这两个属性的组合对于钥匙串中的每个条目都是唯一的."(来自 http://useyourloaf.com/blog/2010/4/28/keychain-duplicate-item-when-adding-password.html).

                  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 http://useyourloaf.com/blog/2010/4/28/keychain-duplicate-item-when-adding-password.html).

                  此外,在使用此代码的 Apple 示例项目中,他们在应用委托中实例化 KeychainItemWrapper.我不知道是否有必要,但我喜欢尽可能地效仿他们的例子:

                  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:

                  - (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];
                  }
                  

                  我认为这是包装代码中的错误.逻辑基本上是说这个条目是否已经存在?不,它不存在.好的,我会添加它.糟糕,你不能添加它,因为它已经存在了."

                  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."

                  您可能还需要设置 kSecAttrAccount;我从未尝试过不设置此值,因为它旨在保存与密码一起使用的用户名:

                  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:

                  [self.wrapper setObject:txtUserName.text forKey:(id)kSecAttrAccount];   
                  

                  这篇关于使用 iphone sdk 在钥匙串中保存时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  EAAccessory/EASession teardown during background(EAAccessory/EASession 在后台拆除)
                  Getting an NSArray of a single attribute from an NSArray(从 NSArray 获取单个属性的 NSArray)
                  ImageIO: lt;ERRORgt; JPEG Corrupt JPEG data: premature end of data segment iphone - how to catch this?(ImageIO:lt;错误gt;JPEG 损坏的 JPEG 数据:iphone 数据段过早结束 - 如何捕捉到这个?)
                  Xcode iOS organizer submit to app store yields quot;The archive is invalidquot; error(Xcode iOS 管理器提交到应用商店产生“存档无效;错误)
                  MFMessageComposeViewController alloc returns nil(MFMessageComposeViewController alloc 返回 nil)
                  How to add and get the values from .plist in iOS(如何在 iOS 中从 .plist 添加和获取值)

                  <small id='qr7Yc'></small><noframes id='qr7Yc'>

                    1. <legend id='qr7Yc'><style id='qr7Yc'><dir id='qr7Yc'><q id='qr7Yc'></q></dir></style></legend>
                        <tbody id='qr7Yc'></tbody>

                      <tfoot id='qr7Yc'></tfoot>

                        • <i id='qr7Yc'><tr id='qr7Yc'><dt id='qr7Yc'><q id='qr7Yc'><span id='qr7Yc'><b id='qr7Yc'><form id='qr7Yc'><ins id='qr7Yc'></ins><ul id='qr7Yc'></ul><sub id='qr7Yc'></sub></form><legend id='qr7Yc'></legend><bdo id='qr7Yc'><pre id='qr7Yc'><center id='qr7Yc'></center></pre></bdo></b><th id='qr7Yc'></th></span></q></dt></tr></i><div id='qr7Yc'><tfoot id='qr7Yc'></tfoot><dl id='qr7Yc'><fieldset id='qr7Yc'></fieldset></dl></div>
                            <bdo id='qr7Yc'></bdo><ul id='qr7Yc'></ul>