Hi, I am trying to use a PeoplePicker to retrieve the name and address of a contact and store it into the NSUserDefaults, which i eventually want to retrieve it on a tableview.
My question is how do I save the information in NSUserDefaults. I have used NSDictionary, but I am not making any progress. so I'm trying to save the array to the NSUserDefaults.
Can someone help me?
My code look like this:
- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker
shouldContinueAfterSelectingPerson:(ABRecordRef)person
property:(ABPropertyID)property
identifier:(ABMultiValueIdentifier)identifier {
// Only inspect the value if it's an address.
if (property == kABPersonAddressProperty) {
ABMutableMultiValueRef multiValue = ABRecordCopyValue(person, property);
for(CFIndex i=0;i<ABMultiValueGetCount(multiValue);i++)
{
ABMultiValueRef multi = ABRecordCopyValue(person, property);
// Set up an NSArray and copy the values in.
NSArray *theArray = [(id)ABMultiValueCopyArrayOfAllValues(multi) autorelease];
// Figure out which values we want and store the index.
const NSUInteger theIndex = ABMultiValueGetIndexForIdentifier(multi, identifier);
// Set up an NSDictionary to hold the contents of the array.
NSDictionary *dictionary = [theArray objectAtIndex:theIndex];
// Set up NSStrings to hold keys and values. First, how many are there?
const NSUInteger theCount = [dictionary count];
NSString *keys[theCount];
NSString *values[theCount];
// Get the keys and values from the CFDictionary. Note that because
// we're using the "GetKeysAndValues" function, you don't need to
// release keys or values. It's the "Get Rule" and only applies to
// CoreFoundation objects.
[dictionary getObjects:values andKeys:keys];
// Set the address label's text.
NSString *address;
address = [NSString stringWithFormat:@"%@, %@, %@",
[dictionary objectForKey:(NSString *)kABPersonAddressStreetKey],
[dictionary objectForKey:(NSString *)kABPersonAddressCityKey],
[dictionary objectForKey:(NSString *)kABPersonAddressCountryKey]];
NSLog(@"%@", address);
[self dismissModalViewControllerAnimated:YES];
[self.navigationController popViewControllerAnimated:YES];
}
NSUserDefaults *locatie = [NSUserDefaults standardUserDefaults];
CFRelease(multiValue);
}
return NO;
}