码迷,mamicode.com
首页 > 其他好文 > 详细

-25299 reason: 'Couldn't add the Keychain Item.'

时间:2015-09-28 16:15:17      阅读:232      评论:0      收藏:0      [点我收藏+]

标签:

今天在用苹果官方demo 提供的KeychainItemWrapper类时遇到-25299  reason: ‘Couldn‘t add the Keychain Item.‘错误,再4s上可以正常运行,但6上却崩溃

崩溃位置

 result = SecItemAdd((CFDictionaryRef)[self dictionaryToSecItemFormat:keychainItemData], NULL);

NSAssert( result == noErr, @"Couldn‘t add the Keychain Item." );

我调用的方法

 

  CFUUIDRef uuidRef = CFUUIDCreate(kCFAllocatorDefault);

        strUUID = (NSString *)CFBridgingRelease(CFUUIDCreateString (kCFAllocatorDefault,uuidRef));

        [keychainItem setObject:strUUID forKey:(__bridge id)kSecValueData];

 

通过看国外的文章知道了方法(http://stackoverflow.com/questions/4309110/error-saving-in-the-keychain-with-iphone-sdk

修改方法: 加上下面这行代码就能正常运行

[keychainItem setObject:@"MY_APP_CREDENTIALS" forKey:(id)kSecAttrService];

最后修改成代码为:

 

        [keychainItem setObject:@"MY_APP_CREDENTIALS" forKey:(id)kSecAttrService];

 

            CFUUIDRef uuidRef = CFUUIDCreate(kCFAllocatorDefault);

 

        strUUID = (NSString *)CFBridgingRelease(CFUUIDCreateString (kCFAllocatorDefault,uuidRef));

 

        [keychainItem setObject:strUUID forKey:(__bridge id)kSecValueData];

 

原因:

  KeyChain内部以kSecAttrAccount 与kSecAttrService作为唯一钥匙串标识,两个都必须设置才行;

 

        

-25299 reason: 'Couldn't add the Keychain Item.'

标签:

原文地址:http://www.cnblogs.com/lingzeng/p/4844029.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!