Adding a phone number and email to your address book crashes in iPhoneApp

ABRecordSetValue(person, kABPersonPhoneProperty, (__bridge CFTypeRef)phoneNum, nil); ABRecordSetValue(person, kABPersonEmailProperty, (__bridge CFTypeRef)eMailId, nil); 

Commenting , these two lines give the correct conclusion (saving the entry in the address book without e-mail and recording by phone). But when executed, it does not work and the program crashes.

Value for Vars:

phoneNum : 000-000-0000

eMailId : AbcdefghIjklm@qwertyuiopasdfghjk.com

Type of error: EXC_BAD_ACCESS

Any idea? Or do you need more information?

+6
source share
2 answers

It would be nice to see where and from what type you define vars. You may also have issued an address book before these lines. (e.g. CFRelease(multiPhone); ) And as far as I know, phoneNum and emailID should be ABMutableMultiValueRef . At least that's what I did:

Adding a single phone number

 ABMutableMultiValueRef multiPhone = ABMultiValueCreateMutable(kABMultiStringPropertyType); ABMultiValueAddValueAndLabel(multiPhone, [self.contact telephone], kABPersonPhoneMobileLabel, NULL); ABRecordSetValue(person, kABPersonPhoneProperty, multiPhone,nil); 

Adding an Email:

  ABMutableMultiValueRef multiEmail = ABMultiValueCreateMutable(kABMultiStringPropertyType); ABMultiValueAddValueAndLabel(multiEmail, @" abc@abc.com ", kABWorkLabel, NULL); ABRecordSetValue(person, kABPersonEmailProperty, multiEmail, &error); CFRelease(multiEmail); 

Additional Information on the Address Book Tutorial

Hope this helps.

+16
source

Try

 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); 

Hope this can be helpful ...

+3
source

Source: https://habr.com/ru/post/904981/


All Articles