How can we store and access a list of ABRecordRef
so that we can use this in another class and later on?
Asked
Active
Viewed 830 times
1

Baby Groot
- 4,637
- 39
- 52
- 71
2 Answers
2
You can get recordId
from the record of type ABRecordRef
from
addressBook Then convert it into NSString
. Store it in NSUserDefaults
When you want to fetch the record...
fetch that recordId
from NSUserDefaults
,Convert it in integer
then use
ABRecordRef myRecord =
ABAddressBookGetPersonWithRecordID(addressBook, recordId);
So you will get the record which you saved earlier.
1
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.

Dave
- 275
- 2
- 14
-
i'm able to fetch the variable person i need to store this variable person in nsuserdefaults or database so that i can retrieve the saved data and manipulate any record later on.. Please guide me for this. – Baby Groot Aug 08 '11 at 13:11
-
Right, so you need to store each piece of information about the person into a dictionary or other collection and then add that dictionary to NSUserDefaults. I'll adjust my answer above. – Dave Aug 08 '11 at 13:20
-
Sorry but even this is not so helpful. Let me give a detail description. I need to create an image with some text and another image on it. That part is already over now i need to set this as profile pic of the person even i'm able to do this if it is in same class. Now if person want to change the text added i need to change the profile pic again for that i need to pass ABRecordRef as a parameter. For this i need to store list of ABRecordRef. – Baby Groot Aug 08 '11 at 13:41