我可能做错了什么,但是当我使用下面的代码并希望 Lockbox 在应用程序第一次启动时将元素保存到钥匙串时,什么都没有存储。如果我然后再次运行应用程序并在 else 部分中添加元素,那么它会保存数据。
有什么建议么?
NSString *value = @"";
NSArray *array = [Lockbox arrayForKey:@"TestKey"];
value = [array componentsJoinedByString:@"|"];
if(value == nil)
{
BOOL result = NO;
NSArray *narray = [NSArray arrayWithObjects:
[value stringByAppendingString:@"key1"],
[value stringByAppendingString:@"key2"],
[value stringByAppendingString:@"|http://www.url.com/"],
[value stringByAppendingString:@"|http://www.url2.com/"],nil];
result = [Lockbox setArray:narray forKey:@"TestKey"];
}else{
NSArray *narray = [NSArray arrayWithObjects:
[value stringByAppendingString:@"key1"],
[value stringByAppendingString:@"key2"],
[value stringByAppendingString:@"|http://www.url.com/"],
[value stringByAppendingString:@"|http://www.url2.com/"],nil];
result = [Lockbox setArray:narray forKey:@"TestKey"];
NSString *keyv1 =[array objectAtIndex:0];
NSLog(@"key value %@",keyv1);
}