Hi all, I am trying to add a contact's info to the device's address book using this code:
Code:
- (IBAction)addContact:(id)sender {
ABAddressBookRef addressBook = ABAddressBookCreate();
ABRecordRef person = ABPersonCreate();
ABMutableMultiValueRef phoneNumberMultiValue = ABMultiValueCreateMutable(kABMultiStringPropertyType);
ABMultiValueAddValueAndLabel(phoneNumberMultiValue,formattedHomeNumber,kABPersonPhoneMainLabel, NULL);
ABMutableMultiValueRef emailMultiValue = ABMultiValueCreateMutable(kABMultiStringPropertyType);
ABMultiValueAddValueAndLabel(emailMultiValue, emailAddress, kABHomeLabel,NULL);
ABRecordSetValue(person, kABPersonFirstNameProperty, firstName , nil);
ABRecordSetValue(person, kABPersonLastNameProperty, lastName, nil);
ABRecordSetValue(person, kABPersonPhoneProperty, phoneNumberMultiValue,nil);
ABAddressBookAddRecord(addressBook, person, nil);
ABAddressBookSave(addressBook, nil);
CFRelease(person);
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Contact Saved Successfully" message:nil delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];
}
The user selects a row from a UITableView and can view a contact's information, then click a button to store that info to the address book. The problem is with storing phone numbers. I can only store one phone number at a time (I would like to use two different fields for the home and mobile number), and the app randomly crashes when trying to enter certain numbers. Thanks in advance!
Greg
P.S. This is an in-house app, so don't worry about any private APIs!