How can we store and access a list of ABRecordRef so that we can use this in another class and later on?
Store array of ABRecordRef
855 Views Asked by Baby Groot At
2
There are 2 best solutions below
3
On
Try This:
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];
That should be it.
You can get
recordIdfrom the record of typeABRecordReffrom addressBook Then convert it intoNSString. Store it inNSUserDefaultsWhen you want to fetch the record...
fetch that
recordIdfromNSUserDefaults,Convert it in integerthen use
So you will get the record which you saved earlier.