0

HI i want to add contacts into my AddressBook in my Application. Like if i have a text field for name and phonenumber, once i click the button it should add into my addressbook.

I went through many questions in stackoverflow How to add a contact from my app to the iOS address book but i didnt understand so can anyone tel me how to implement this with sample code or if u have any tutorial link regarding this it would be great.

Community
  • 1
  • 1
Abhilash
  • 638
  • 4
  • 11
  • 28
  • the link you mentioned has the perfect answer and code. What you dint understood from that? – Durgaprasad May 24 '13 at 05:07
  • You can try with this apple doc: http://developer.apple.com/library/ios/#documentation/ContactData/Conceptual/AddressBookProgrammingGuideforiPhone/Chapters/UI_Controllers.html#//apple_ref/doc/uid/TP40007744-CH5-SW1 – pankaj asudani May 24 '13 at 05:12
  • @Durgaprasad i didnt understand if i have a texfield once i enter the relevant data like name and phonenumber how do i save into addressbook..in the above link there are lot of information added and i didnt understand delegate method – Abhilash May 24 '13 at 05:14

1 Answers1

0

if you want to add adress of a person with image this will help you sir
First you will have to make ABAddressBookRef object.

ABAddressBookRef addressBook = ABAddressBookCreate();
    ABRecordRef person = ABPersonCreate();
    // Add Person Image

    NSData *dataRef = UIImagePNGRepresentation(personImageView.image);
    ABPersonSetImageData(person, (CFDataRef)dataRef, nil);

    CFErrorRef  anError = NULL;
    // Full Name, Company Name, Designation Property

    ABRecordSetValue(person,kABPersonFirstNameProperty,full_name,&anError);
    ABRecordSetValue(person, kABPersonOrganizationProperty, companyLabel, &anError);
    ABRecordSetValue(person, kABPersonJobTitleProperty, designation, &anError);
    // Multi value Address Property

    ABMutableMultiValueRef multiAddress = ABMultiValueCreateMutable(kABMultiDictionaryPropertyType);'
    NSMutableDictionary *addressDictionary = [[NSMutableDictionary alloc] init];

    [addressDictionary setObject:@"Chicago" forKey:(NSString *)kABPersonAddressCityKey];
    [addressDictionary setObject:@"IL" forKey:(NSString *)kABPersonAddressStateKey];
    [addressDictionary setObject:@"60654" forKey:(NSString *)kABPersonAddressZIPKey];

    ABMultiValueAddValueAndLabel(multiAddress, addressDictionary, (CFStringRef)@"Address", NULL);
    ABRecordSetValue(person, kABPersonAddressProperty, multiAddress,&anError);
    CFRelease(multiAddress);

    ABMutableMultiValueRef websiteMultiValue = ABMultiValueCreateMutable(kABPersonURLProperty);
    ABMultiValueAddValueAndLabel(websiteMultiValue, web_URL, (CFStringRef)@"Website", NULL);
    ABRecordSetValue(person, kABPersonURLProperty, websiteMultiValue, &anError);


    ABMutableMultiValueRef emailMultiValue = ABMultiValueCreateMutable(kABPersonEmailProperty);
    ABMultiValueAddValueAndLabel(emailMultiValue, email, (CFStringRef)@"Email", NULL);
    ABRecordSetValue(person, kABPersonEmailProperty, emailMultiValue, &anError);

    ABAddressBookAddRecord(addressBook, person, &anError);

hope this help sir..