尝试将数据写入Keychain时断言失败

时间:2013-07-22 01:58:59

标签: ios nsarray nsdata keychain

我正在尝试使用下面的代码将一些数组数据写入我的钥匙串

    // set up keychain so I can write to it... or read if needed (specially for testing)
    KeychainItemWrapper* keychain = [[KeychainItemWrapper alloc] initWithIdentifier:@"KeyKeychain" accessGroup:nil];

//    write
    NSData *dataarr = [NSKeyedArchiver archivedDataWithRootObject:parsedRemoteSitesMutableArray];
     [keychain setObject:dataarr forKey:(__bridge id)(kSecAttrGeneric)];
//    read
    NSData *myArr = [keychain objectForKey:(__bridge id)(kSecAttrGeneric)];
    NSArray *arrayCopy = [NSKeyedUnarchiver unarchiveObjectWithData:myArr];
//    log
    NSLog(@"%@", arrayCopy);

你可以看到我正在将我的NSArray转换为NSData,然后尝试将NSData存储到kSecAttrGeneric但是当我对setObject:forKey

时,我正在收到此错误
Assertion failure in -[KeychainItemWrapper writeToKeychain], /Users/imac/Documents/Iphone applications/appname/appname/KeychainItemWrapper.m:268
2013-07-22 13:54:39.952 key[2167:907] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Couldn't add the Keychain Item.'
*** First throw call stack:etc...

任何帮助将不胜感激。

0 个答案:

没有答案