Adding phone number and email to addressbook gives crash in iPhoneApp
Asked Answered
K

2

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

Kirst answered 3/1, 2012 at 12:27 Comment(1)
can you please provide the detail information.What do you want to do actually..?Lahr
O
16

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.

Oosperm answered 3/1, 2012 at 12:48 Comment(3)
I need to set just a single phone number and single mail id. Both of them i have taken of type NSString*, and then converted them, into CFStringRef.Kirst
Edited my answer. But what do you mean by mail id? something different than a mail address?Subsist
dead link for address book tutorialJack
L
2

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

Lahr answered 3/1, 2012 at 12:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.