我们如何存储和访问ABRecordRef列表,以便我们可以在另一个类中使用它,并在以后使用它?
发布于 2011-08-09 20:31:01
您可以从addressBook的ABRecordRef类型的记录中获取recordId,然后将其转换为NSString。将其存储在NSUserDefaults中
当你想取回记录的时候...
从NSUserDefaults获取recordId,将其转换为整数
然后使用
ABRecordRef myRecord =
ABAddressBookGetPersonWithRecordID(addressBook, recordId);因此,您将获得之前保存的记录。
发布于 2011-08-08 21:08:38
试试这个:
ABAddressBookRef addressBook = ABAddressBookCreate();
ABRecordRef person = ABRecordGetRecordID(1); // Or whatever you're using to get the record.
// do this for each piece of information you need:
NSString *firstName = (NSString *)ABRecordCopyValue(person, kABPersonFirstNameProperty);
NSString *lastName = (NSString *)ABRecordCopyValue(person, kABPersonLastNameProperty);
// Get your receiving dict ready:
NSMutableDictionary *personDict = [NSMutableDictionary dictionary];
// then test them for a value (don't want nil values in the dictionary)
// Add each value as you test it.
if (firstName) {
[personDict setObject:firstName forKey:@"FistName"];
}
if (lastName) {
[personDict setObject:lastName forKey:@"LastName"];
}
// Add the personDict to NSUserDefaults:
[[NSUserDefaults standardDefaults] setObject:personDict forKey:@"MyPersonsDictionary"];
// Clean up after yourself:
[firstName release];
[lastNmae release];应该就是这样了。
https://stackoverflow.com/questions/6982556
复制相似问题