Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding phone number and email to addressbook gives crash in iPhoneApp

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??

like image 607
viral Avatar asked Jan 03 '12 12:01

viral


2 Answers

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.

like image 132
Eren Beşel Avatar answered Nov 09 '22 11:11

Eren Beşel


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 ...

like image 2
Kamar Shad Avatar answered Nov 09 '22 11:11

Kamar Shad