Adding contact into ios addressbook - iphone

I want to add contacts into my address book. I am developing an app where I have gone through many links, and I have following code, but now I am stuck.
I have imported:
#import <AddressBook/AddressBook.h>
#import <AddressBookUI/AddressBookUI.h
in viewcontroller.m:
-(IBAction)addToAddressbook:(id)sender{
ABUnknownPersonViewController *unknownPersonViewController = [[ABUnknownPersonViewController alloc] init];
unknownPersonViewController.displayedPerson = (ABRecordRef)[self buildContactDetails];
unknownPersonViewController.allowsAddingToAddressBook = YES;
[self.navigationController pushViewController:unknownPersonViewController animated:YES];
[unknownPersonViewController release];
}
- (ABRecordRef)buildContactDetails {
NSLog(#"building contact details");
ABRecordRef person = ABPersonCreate();
CFErrorRef error = NULL;
// firstname
ABRecordSetValue(person, kABPersonFirstNameProperty, #"Don Juan", NULL);
// email
ABMutableMultiValueRef email = ABMultiValueCreateMutable(kABMultiStringPropertyType);
ABMultiValueAddValueAndLabel(email, #"expert.in#computer.com", CFSTR("email"), NULL);
ABRecordSetValue(person, kABPersonEmailProperty, email, &error);
CFRelease(email);
// Start of Address
ABMutableMultiValueRef address = ABMultiValueCreateMutable(kABMultiDictionaryPropertyType);
NSMutableDictionary *addressDict = [[NSMutableDictionary alloc] init];
[addressDict setObject:#"The awesome road numba 1" forKey:(NSString *)kABPersonAddressStreetKey];
[addressDict setObject:#"0568" forKey:(NSString *)kABPersonAddressZIPKey];
[addressDict setObject:#"Oslo" forKey:(NSString *)kABPersonAddressCityKey];
ABMultiValueAddValueAndLabel(address, addressDict, kABWorkLabel, NULL);
ABRecordSetValue(person, kABPersonAddressProperty, address, &error);
[addressDict release];
CFRelease(address);
// End of Address
if (error != NULL)
NSLog(#"Error: %#", error);
[(id)person autorelease];
return person;
}
In UI I have an IBAction button connected to addToAddressbook, but on click, nothing is happening - so what else to do I need to do in UI or in the code?

After looking at your code i can see that you are missing the ABAddressBookSave statement. After setting the values of
// firstname
ABRecordSetValue(person, kABPersonFirstNameProperty, #"Don Juan", NULL);
// email
ABRecordSetValue(person, kABPersonEmailProperty, email, &error);
// Address
ABRecordSetValue(person, kABPersonAddressProperty, address, &error);
You should call ABAddressBookSave which is as follows.
ABAddressBookSave(ABAddressBookRef addressBook, CFErrorRef* error);

Related

ABAddressBookGetPersonWithRecordID crash the app when recordId not available

In my app I've stored ABPropertyID in database and based on that I've displayed number of ABRecordRef with ABAddressBookGetPersonWithRecordID(addressBook, recordID). But when contact deleted in contacts and I try to get ABRecordRef, App crashes is obvious.
So my question is:
Is there any way to check that recordID is available in addressBook?
This function does not throw an exception, but it returns NULL if there is no record with this ID.
See: http://developer.apple.com/library/ios/ipad/#documentation/AddressBook/Reference/ABPersonRef_iPhoneOS/Reference/reference.html
try this one
ABAddressBookRef addressBookRef = ABAddressBookCreateWithOptions(NULL, NULL);
if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusNotDetermined) {
ABAddressBookRequestAccessWithCompletion(addressBookRef, ^(bool granted, CFErrorRef error) {
// First time access has been granted, add the contact
ABAddressBookRef iPhoneAddressBook = ABAddressBookCreateWithOptions(NULL, NULL);
ABRecordRef newPerson = ABPersonCreate();
ABRecordSetValue(newPerson, kABPersonSortByFirstName,(__bridge CFTypeRef)(firstname),&error);
ABRecordSetValue(newPerson, kABPersonLastNameProperty,(__bridge CFTypeRef)(lastname), &error);
ABRecordSetValue(newPerson, kABPersonOrganizationProperty, #"", &error);
ABRecordSetValue(newPerson, kABPersonJobTitleProperty,#"", &error);
ABMutableMultiValueRef multiPhone = ABMultiValueCreateMutable(kABMultiStringPropertyType);
ABMultiValueAddValueAndLabel(multiPhone, (__bridge CFTypeRef)(contact_phone), kABPersonPhoneMainLabel, NULL);
ABMultiValueAddValueAndLabel(multiPhone, #"", kABPersonPhoneMobileLabel, NULL);
ABMultiValueAddValueAndLabel(multiPhone, #"", kABOtherLabel, NULL);
ABRecordSetValue(newPerson, kABPersonPhoneProperty, multiPhone,nil);
CFRelease(multiPhone);
ABMutableMultiValueRef multiEmail = ABMultiValueCreateMutable(kABMultiStringPropertyType);
ABMultiValueAddValueAndLabel(multiEmail,(__bridge CFTypeRef)(contact_email) , kABWorkLabel, NULL);
ABRecordSetValue(newPerson, kABPersonEmailProperty, multiEmail, &error);
CFRelease(multiEmail);
// ABMutableMultiValueRef multiAddress = ABMultiValueCreateMutable(kABMultiDictionaryPropertyType);
// NSMutableDictionary *addressDictionary = [[NSMutableDictionary alloc] init];
// [addressDictionary setObject:#"750 North Orleans Street, Ste 601" forKey:(NSString *) kABPersonAddressStreetKey];
// [addressDictionary setObject:#"Chicago" forKey:(NSString *)kABPersonAddressCityKey];
// [addressDictionary setObject:#"IL" forKey:(NSString *)kABPersonAddressStateKey];
// [addressDictionary setObject:#"60654" forKey:(NSString *)kABPersonAddressZIPKey];
// ABMultiValueAddValueAndLabel(multiAddress, addressDictionary, kABWorkLabel, NULL);
// ABRecordSetValue(newPerson, kABPersonAddressProperty, multiAddress,&error);
// CFRelease(multiAddress);
ABAddressBookAddRecord(iPhoneAddressBook, newPerson, &error);
ABAddressBookSave(iPhoneAddressBook, &error);
if (error != NULL)
{
NSLog(#"Danger Will Robinson! Danger!");
}
// ABAddressBookRef addressBook = ABAddressBookCreate();
});
}
else if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusAuthorized) {
CFErrorRef error = NULL;
// ABAddressBookRef addressBook =ABAddressBookCreateWithOptions(NULL, NULL);
ABAddressBookRef iPhoneAddressBook = ABAddressBookCreateWithOptions(NULL, NULL);
ABRecordRef newPerson = ABPersonCreate();
ABRecordSetValue(newPerson, kABPersonSortByFirstName,(__bridge CFTypeRef)(firstname),&error);
NSLog(#"%#",(__bridge CFTypeRef)(firstname));
ABRecordSetValue(newPerson, kABPersonLastNameProperty,(__bridge CFTypeRef)(lastname), &error);
NSLog(#"%#",(__bridge CFTypeRef)(lastname));
ABRecordSetValue(newPerson, kABPersonOrganizationProperty, #"", &error);
ABRecordSetValue(newPerson, kABPersonJobTitleProperty,#"", &error);
ABMutableMultiValueRef multiPhone = ABMultiValueCreateMutable(kABMultiStringPropertyType);
ABMultiValueAddValueAndLabel(multiPhone,(__bridge CFTypeRef)(contact_phone), kABPersonPhoneMainLabel, NULL);
ABMultiValueAddValueAndLabel(multiPhone, #"", kABPersonPhoneMobileLabel, NULL);
ABMultiValueAddValueAndLabel(multiPhone, #"", kABOtherLabel, NULL);
ABRecordSetValue(newPerson, kABPersonPhoneProperty, multiPhone,nil);
CFRelease(multiPhone);
ABMutableMultiValueRef multiEmail = ABMultiValueCreateMutable(kABMultiStringPropertyType);
ABMultiValueAddValueAndLabel(multiEmail, (__bridge CFTypeRef)(contact_email), kABWorkLabel, NULL);
ABRecordSetValue(newPerson, kABPersonEmailProperty, multiEmail, &error);
CFRelease(multiEmail);
// ABMutableMultiValueRef multiAddress = ABMultiValueCreateMutable(kABMultiDictionaryPropertyType);
// NSMutableDictionary *addressDictionary = [[NSMutableDictionary alloc] init];
// [addressDictionary setObject:#"750 North Orleans Street, Ste 601" forKey:(NSString *) kABPersonAddressStreetKey];
// [addressDictionary setObject:#"Chicago" forKey:(NSString *)kABPersonAddressCityKey];
// [addressDictionary setObject:#"IL" forKey:(NSString *)kABPersonAddressStateKey];
// [addressDictionary setObject:#"60654" forKey:(NSString *)kABPersonAddressZIPKey];
// ABMultiValueAddValueAndLabel(multiAddress, addressDictionary, kABWorkLabel, NULL);
// ABRecordSetValue(newPerson, kABPersonAddressProperty, multiAddress,&error);
// CFRelease(multiAddress);
ABAddressBookAddRecord(iPhoneAddressBook, newPerson, &error);
ABAddressBookSave(iPhoneAddressBook, &error);
alertvalue++;
if (error != NULL)
{
NSLog(#"Error not found!");
}
// ABAddressBookRef addressBook = ABAddressBookCreate();
}
else {
// The user has previously denied access
// Send an alert telling user to change privacy setting in settings app
} }

Code get crashing at adding phone contacts query

I am able to add only showroom name to my contacts. But when I put the code to add phone numbers, further details....my code get crash. Any suggestion would be appreciated. Here is my code
- (IBAction)AddContact
{
ABAddressBookRef addressBook = ABAddressBookCreate();
ABRecordRef Showroom = ABPersonCreate();
//adding contact name as showroom name
ABRecordSetValue(Showroom, kABPersonFirstNameProperty, ShowroomName.text , nil);
//adding phone number
ABMutableMultiValueRef multiPhone = ABMultiValueCreateMutable(kABMultiStringPropertyType);
ABMultiValueAddValueAndLabel(multiPhone, p_BcardLabel.text, kABPersonPhoneMainLabel, NULL);
ABRecordSetValue(Showroom, kABPersonPhoneProperty, multiPhone,nil);
CFRelease(multiPhone);
//adding emailaddress
ABMutableMultiValueRef multiEmail = ABMultiValueCreateMutable(kABMultiStringPropertyType);
ABMultiValueAddValueAndLabel(multiEmail, email_BcardLabel.text, kABWorkLabel, NULL);
ABRecordSetValue(Showroom, kABPersonEmailProperty, multiEmail, #"");
CFRelease(multiEmail);
//adding URL
ABMutableMultiValueRef multiURL = ABMultiValueCreateMutable(kABMultiStringPropertyType);
ABMultiValueAddValueAndLabel(multiURL, url_BcardLabel.text, kABHomeLabel, NULL);
ABRecordSetValue(Showroom, kABPersonURLProperty, multiURL, #"");
CFRelease(multiURL);
Shows following message
[Switching to thread 11779]
warning: Unable to read symbols for /Developer/Platforms/iPhoneOS.platform/DeviceSupport/4.3.2 (8H7)/Symbols/Developer/usr/lib/libXcodeDebuggerSupport.dylib (file not found).
If you want only to improve your code. I have checked once your code its fine working just add the following lines
ABAddressBookAddRecord(addressBook,Showroom, nil);
ABAddressBookSave(addressBook,nil);
objABPersonViewController=[[ABUnknownPersonViewController alloc]init];
objABPersonViewController.displayedPerson=Showroom;
[self.navigationController pushViewController:objABPersonViewController animated:YES];
CFRelease(Showroom);
And if you want to use mine check this out. It will also add an image named abc.png from your resource folder to the contact list.
-(IBAction)addToAddressbook:(id)sender{
NSString *fname=#"Person First Name";
NSString *lname=#"Person Last Name";
NSArray *arrayAdd=[[NSArray alloc]initWithObjects:#"street Name",#"city Name",#"country code",#"zip",nil];
UIImage *image=[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:#"abc.png" ofType:nil]];
[self addContact:fname:lname:arrayAdd:image];
}
-(void) addContact:(NSString *)firstname:(NSString *)lastname:(NSArray *)arrayAddress:(UIImage *)currentImage
{
ABAddressBookRef addressBook=ABAddressBookCreate();
ABRecordRef person=ABPersonCreate();
//set Image
NSData * dataRef = UIImagePNGRepresentation(currentImage);
ABPersonSetImageData(person, (CFDataRef)dataRef, nil);
//set FirstName and LastName
ABRecordSetValue(person, kABPersonFirstNameProperty,firstname, nil);
ABRecordSetValue(person, kABPersonLastNameProperty,lastname, nil);
//Add Address
ABMutableMultiValueRef address=ABMultiValueCreateMutable(kABMultiDictionaryPropertyType);
NSMutableDictionary *addressDictionary=[[NSMutableDictionary alloc]init];
[addressDictionary setObject:[arrayAddress objectAtIndex:0] forKey:(NSString *)kABPersonAddressStreetKey];
[addressDictionary setObject:[arrayAddress objectAtIndex:1]forKey:(NSString *)kABPersonAddressCityKey];
[addressDictionary setObject:[arrayAddress objectAtIndex:2] forKey:(NSString *)kABPersonAddressCountryCodeKey];
[addressDictionary setObject:[arrayAddress objectAtIndex:3] forKey:(NSString *)kABPersonAddressCountryKey];
ABMultiValueAddValueAndLabel(address, addressDictionary, kABHomeLabel, nil);
ABRecordSetValue(person, kABPersonAddressProperty, address, nil);
ABAddressBookAddRecord(addressBook,person, nil);
ABAddressBookSave(addressBook,nil);
objABPersonViewController=[[ABUnknownPersonViewController alloc]init];
objABPersonViewController.displayedPerson=person;
[self.navigationController pushViewController:objABPersonViewController animated:YES];
CFRelease(person);
}
for any further query just ask... Happy to help
This is the Answer to your question Navnath. Apple provides ABNewPersonViewController to open the particular add contact view.Add the ABNewPersonViewControllerDelegate in your header file.
case 1:Application is view based:-
-(IBAction)displayContactAddWindow:(id)sender{
ABNewPersonViewController *picker = [[ABNewPersonViewController alloc] init];
picker.newPersonViewDelegate = self;
UINavigationController *navigation = [[UINavigationController alloc] initWithRootViewController:picker];
[self presentModalViewController:navigation animated:YES];
[picker release];
[navigation release];
}
case 2:Application is navigation based:-
-(IBAction)displayContactAddWindow:(id)sender{
ABNewPersonViewController *picker = [[ABNewPersonViewController alloc] init];
picker.newPersonViewDelegate = self;
[self.navigationController pushViewController:picker animated:YES];
[picker release];
}
- (void)newPersonViewController:(ABNewPersonViewController *)newPersonView didCompleteWithNewPerson:(ABRecordRef)person{
[self.navigationController popViewControllerAnimated:YES];
}

Address book implementation not working

I am using XCode 4.2 to develop a function to add a contact to the address book , here is my code
ABAddressBookRef *iPhoneAddressBook = ABAddressBookCreate();
ABRecordRef contact = ABPersonCreate();
//add infos
ABRecordSetValue(contact, kABPersonFirstNameProperty,(__bridge_retained CFStringRef)firstName, nil);
ABRecordSetValue(contact, kABPersonLastNameProperty,(__bridge_retained CFStringRef)lastName, nil);
ABRecordSetValue(contact, kABPersonOrganizationProperty, (__bridge_retained CFStringRef)organization, nil);
ABRecordSetValue(contact, kABPersonJobTitleProperty, (__bridge_retained CFStringRef)title, nil);
ABMultiValueRef multiPhone = ABMultiValueCreateMutable(kABMultiRealPropertyType);
ABMultiValueAddValueAndLabel(multiPhone, (__bridge_retained CFStringRef)workTel, kABPersonPhoneMainLabel, NULL);
ABMultiValueAddValueAndLabel(multiPhone, (__bridge_retained CFStringRef)workFax, kABPersonPhoneWorkFAXLabel, NULL);
ABRecordSetValue(contact, kABPersonPhoneProperty, multiPhone, nil);
CFRelease(multiPhone);
ABMultiValueRef multiEmail = ABMultiValueCreateMutable(kABMultiStringPropertyType);
ABMultiValueAddValueAndLabel(multiEmail, (__bridge_retained CFStringRef)email, kABWorkLabel, NULL);
ABRecordSetValue(contact, kABPersonEmailProperty, multiEmail, nil);
CFRelease(multiEmail);
// address
ABMultiValueRef multiAddress =ABMultiValueCreateMutable(kABMultiDictionaryPropertyType);
NSMutableDictionary *addressDict = [[NSMutableDictionary alloc]init];
[addressDict setObject:address forKey:(NSString *) kABPersonAddressStreetKey];
[addressDict setObject:city forKey:(NSString *) kABPersonAddressCityKey];
[addressDict setObject:province forKey:(NSString *) kABPersonAddressStateKey];
[addressDict setObject:postalCode forKey:(NSString *) kABPersonAddressZIPKey];
[addressDict setObject:address forKey:(NSString *) kABPersonAddressCountryKey];
ABMultiValueAddValueAndLabel(multiAddress, (__bridge_retained CFStringRef)addressDict, kABWorkLabel, NULL);
ABRecordSetValue(contact, kABPersonAddressProperty, multiAddress, NULL);
CFRelease(multiAddress);
ABMultiValueRef multiURL =ABMultiValueCreateMutable(kABMultiRealPropertyType);
ABMultiValueAddValueAndLabel(multiURL, (__bridge_retained CFStringRef)link, kABPersonURLProperty, NULL);
CFRelease(multiURL);
ABAddressBookAddRecord(iPhoneAddressBook, contact, nil);
BOOL didAdd = ABAddressBookSave(iPhoneAddressBook, nil);
CFRelease(contact);
CFRelease(iPhoneAddressBook);
//notifying the user that it was stored in his address book
if (didAdd) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Confirmation"
message:#"Contact Info successfully added to the Address Book"
delegate:self
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
}
the program compiles and but it stops at this line :
ABMultiValueAddValueAndLabel(multiPhone, (__bridge_retained CFStringRef)workTel, kABPersonPhoneMainLabel, NULL);
I get this error (in green)
Thread 1
any clue ? what is wrong in the code ?
This is the definition of the function in which your error occurs:
bool ABMultiValueAddValueAndLabel (
ABMutableMultiValueRef multiValue,
CFTypeRef value,
CFStringRef label,
ABMultiValueIdentifier *outIdentifier
);
It appears you have switched the 2nd and 3rd arguments, right?

How to display a person record just after saving his data to iPhone Address Book?

this is my code and it works flawless, where my_value is a string with separator ','.
everythign works fin but i'd like to display the person record from the address book after i saved it, so in the function
if(isSaved) {
// **** code here ***
}
here the complete function
- (void) addToAgenda: (NSString*) my_value{
//NSArray *strings = [my_value componentsSeparatedByString: #","];
NSArray *dati=[[NSArray alloc] initWithArray:[my_value componentsSeparatedByString:#","]];
NSString *userwebsite = [dati objectAtIndex:0];
NSString *fname = [dati objectAtIndex:1];
NSString *lname = [dati objectAtIndex:2];
NSString *useremail = [dati objectAtIndex:3];;
NSString *usermobile = [dati objectAtIndex:4];
NSString *usercompany = #"xxx";
ABRecordRef aRecord = ABPersonCreate();
CFErrorRef anError = NULL;
// fisrst name
ABRecordSetValue(aRecord, kABPersonFirstNameProperty, fname, &anError);
// last name
ABRecordSetValue(aRecord, kABPersonLastNameProperty, lname, &anError);
// Phone Number.
ABMutableMultiValueRef multi = ABMultiValueCreateMutable(kABMultiStringPropertyType);
ABMultiValueAddValueAndLabel(multi, (CFStringRef)usermobile, kABWorkLabel, NULL);
ABRecordSetValue(aRecord, kABPersonPhoneProperty, multi, &anError);
CFRelease(multi);
// Company
ABRecordSetValue(aRecord, kABPersonDepartmentProperty, usercompany, &anError);
// email
NSLog(#"%#", useremail);
ABMutableMultiValueRef multiemail = ABMultiValueCreateMutable(kABMultiStringPropertyType);
ABMultiValueAddValueAndLabel(multiemail, (CFStringRef)useremail, kABWorkLabel, NULL);
ABRecordSetValue(aRecord, kABPersonEmailProperty, multiemail, &anError);
CFRelease(multiemail);
// website
NSLog(#"%#", userwebsite);
ABMutableMultiValueRef multiweb = ABMultiValueCreateMutable(kABMultiStringPropertyType);
ABMultiValueAddValueAndLabel(multiweb, (CFStringRef)userwebsite, kABWorkLabel, NULL);
ABRecordSetValue(aRecord, kABPersonURLProperty, multiweb, &anError);
CFRelease(multiemail);
if (anError != NULL)
NSLog(#"error while creating..");
CFStringRef personname, personlname, personcompind, personemail, personwebsite, personcontact;
personname = ABRecordCopyValue(aRecord, kABPersonFirstNameProperty);
personlname = ABRecordCopyValue(aRecord, kABPersonLastNameProperty);
personcompind = ABRecordCopyValue(aRecord, kABPersonDepartmentProperty);
personemail = ABRecordCopyValue(aRecord, kABPersonEmailProperty);
personwebsite = ABRecordCopyValue(aRecord, kABPersonURLProperty);
personcontact = ABRecordCopyValue(aRecord, kABPersonPhoneProperty);
ABAddressBookRef addressBook;
CFErrorRef error = NULL;
addressBook = ABAddressBookCreate();
BOOL isAdded = ABAddressBookAddRecord (addressBook, aRecord, &error);
if(isAdded){
NSLog(#"added..");
}
if (error != NULL) {
NSLog(#"ABAddressBookAddRecord %#", error);
}
error = NULL;
BOOL isSaved = ABAddressBookSave (addressBook, &error);
if(isSaved) {
// **** code here ***
}
if (error != NULL) {
NSLog(#"ABAddressBookSave %#", error);
UIAlertView *alertOnChoose = [[UIAlertView alloc] initWithTitle:#"Unable to save this time" message:nil delegate:self cancelButtonTitle:nil otherButtonTitles:#"Ok", nil];
[alertOnChoose show];
[alertOnChoose release];
}
CFRelease(aRecord);
CFRelease(personname);
CFRelease(personlname);
CFRelease(personcompind);
CFRelease(personcontact);
CFRelease(personemail);
CFRelease(personwebsite);
CFRelease(addressBook);
}
You can use something like ABPersonViewController to display aRecord. Since it is a subclass of UIViewController, you can show it just like any other view controller, such as pushing it onto your navigation controller stack or presenting it modally.

Add contact to addressbook in iphone objective-c

What is the correct way to set street address etc in addressbook and let the user save it on iphone?
EDIT: removed the specific code-problem and made it more general
This is a complete working sample of how to show an person by creating an ABRecordRef and pushing it into the view using an viewcontroller
/////////////////////////////
Hook it up to a custom action.
-(IBAction)addToAddressbook:(id)sender{
ABUnknownPersonViewController *unknownPersonViewController = [[ABUnknownPersonViewController alloc] init];
unknownPersonViewController.displayedPerson = (ABRecordRef)[self buildContactDetails];
unknownPersonViewController.allowsAddingToAddressBook = YES;
[self.navigationController pushViewController:unknownPersonViewController animated:YES];
[unknownPersonViewController release];
}
////////////////////////////
This is the guy that builds the ABrecordRef
- (ABRecordRef)buildContactDetails {
NSLog(#"building contact details");
ABRecordRef person = ABPersonCreate();
CFErrorRef error = NULL;
// firstname
ABRecordSetValue(person, kABPersonFirstNameProperty, #"Don Juan", NULL);
// email
ABMutableMultiValueRef email = ABMultiValueCreateMutable(kABMultiStringPropertyType);
ABMultiValueAddValueAndLabel(email, #"expert.in#computer.com", CFSTR("email"), NULL);
ABRecordSetValue(person, kABPersonEmailProperty, email, &error);
CFRelease(email);
// Start of Address
ABMutableMultiValueRef address = ABMultiValueCreateMutable(kABMultiDictionaryPropertyType);
NSMutableDictionary *addressDict = [[NSMutableDictionary alloc] init];
[addressDict setObject:#"The awesome road numba 1" forKey:(NSString *)kABPersonAddressStreetKey];
[addressDict setObject:#"0568" forKey:(NSString *)kABPersonAddressZIPKey];
[addressDict setObject:#"Oslo" forKey:(NSString *)kABPersonAddressCityKey];
ABMultiValueAddValueAndLabel(address, addressDict, kABWorkLabel, NULL);
ABRecordSetValue(person, kABPersonAddressProperty, address, &error);
[addressDict release];
CFRelease(address);
// End of Address
if (error != NULL)
NSLog(#"Error: %#", error);
[(id)person autorelease];
return person;
}
////////////////////////////
Wire up in the header:
Remember to import these frameworks:
#import <AddressBook/AddressBook.h>
#import <AddressBookUI/AddressBookUI.h>
Set the delegate
ABNewPersonViewControllerDelegate
And add this to the interface
ABNewPersonViewController *newPersonController;
From eyeballing it, I think instead of
ABMutableMultiValueRef address = ABMultiValueCreateMutable(kABMultiStringPropertyType);
you want
ABMutableMultiValueRef address = ABMultiValueCreateMutable(kABDictionaryPropertyType);