首页 > 其他 > 详细

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

时间:2015-09-28 16:15:10      阅读:4534      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!