ABRecordSetValue(person, kABPersonPhoneProperty, (__bridge CFTypeRef)phoneNum, nil);
ABRecordSetValue(person, kABPersonEmailProperty, (__bridge CFTypeRef)eMailId, nil);
Commenting these two lines gives proper output (Saving the entry to AdressBook, without email and phone entry). But, while in execution it fails and crashes the program.
Value for the Vars are:
phoneNum : 000-000-0000
eMailId : [email protected]
Error type: EXC_BAD_ACCESS
Any Idea? Or need any more info??
It would be good to see where and of what type you define the vars. You may have also released the address book before those lines. (e.g. CFRelease(multiPhone);
)
And as far as I know, phoneNum
and emailID
should be ABMutableMultiValueRef
. At least that was how I did it:
Adding a single phone number
ABMutableMultiValueRef multiPhone = ABMultiValueCreateMutable(kABMultiStringPropertyType);
ABMultiValueAddValueAndLabel(multiPhone, [self.contact telephone], kABPersonPhoneMobileLabel, NULL);
ABRecordSetValue(person, kABPersonPhoneProperty, multiPhone,nil);
Adding e-mail:
ABMutableMultiValueRef multiEmail = ABMultiValueCreateMutable(kABMultiStringPropertyType);
ABMultiValueAddValueAndLabel(multiEmail, @"[email protected]", kABWorkLabel, NULL);
ABRecordSetValue(person, kABPersonEmailProperty, multiEmail, &error);
CFRelease(multiEmail);
More info on Address Book tutorial
Hope this helps.
Try This
ABAddressBookRef addressBook = ABAddressBookCreate();
ABRecordRef person = ABPersonCreate();
ABMutableMultiValueRef phoneNumberMultiValue
=ABMultiValueCreateMutable(kABPersonPhoneProperty);
//phoneNumber is the number to be save in Address Book
ABMultiValueAddValueAndLabel(phoneNumberMultiValue ,phoneNumber,kABPersonPhoneMobileLabel, NULL);
//EmailId is the emailId to be save in Address Book
ABMultiValueAddValueAndLabel(phoneNumberMultiValue ,EmailId,kABPersonPhoneMobileLabel, NULL);
ABRecordSetValue(person, kABPersonPhoneProperty, phoneNumberMultiValue,nil);
// set the phone number property
ABAddressBookAddRecord(addressBook, person, nil);
ABAddressBookSave(addressBook, nil);
CFRelease(person);
I Hope it may be helpfull ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With