2012-01-03 29 views
6
ABRecordSetValue(person, kABPersonPhoneProperty, (__bridge CFTypeRef)phoneNum, nil); 
ABRecordSetValue(person, kABPersonEmailProperty, (__bridge CFTypeRef)eMailId, nil); 

Bình luận hai dòng sau cho sản lượng thích hợp (Tiết kiệm entry để AdressBook, không có email, nhập cảnh điện thoại). Nhưng, trong khi thực hiện nó không thành công và treo chương trình.Thêm số điện thoại và email để addressbook cho vụ tai nạn trong iPhoneApp

Value for the Vars là:

phoneNum: 000-000-0000

EmailId: [email protected]

loại Lỗi: EXC_BAD_ACCESS

Bất cứ ý tưởng ? Hoặc cần thêm thông tin?

+0

bạn có thể vui lòng cung cấp chi tiết information.What nào bạn muốn làm thực sự ..? – Kamarshad

Trả lời

16

Sẽ rất hữu ích nếu bạn thấy vị trí và loại bạn xác định các vars. Bạn cũng có thể đã phát hành sổ địa chỉ trước những dòng đó. (ví dụ: CFRelease(multiPhone);) Và theo như tôi biết, phoneNumemailID phải là ABMutableMultiValueRef. Ít nhất đó là làm thế nào tôi đã làm nó:

Thêm một đơn số điện thoại

ABMutableMultiValueRef multiPhone = ABMultiValueCreateMutable(kABMultiStringPropertyType); 

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

Thêm e-mail:

ABMutableMultiValueRef multiEmail = ABMultiValueCreateMutable(kABMultiStringPropertyType); 
    ABMultiValueAddValueAndLabel(multiEmail, @"[email protected]", kABWorkLabel, NULL); 
    ABRecordSetValue(person, kABPersonEmailProperty, multiEmail, &error); 
    CFRelease(multiEmail); 

Thông tin thêm về Address Book tutorial

Hope this helps .

+0

Tôi chỉ cần đặt một số điện thoại và một id thư duy nhất. Cả hai người trong số họ tôi đã lấy loại NSString *, và sau đó chuyển đổi chúng thành CFStringRef. – viral

+0

Đã chỉnh sửa câu trả lời của tôi. Nhưng bạn có ý nghĩa gì với id thư? cái gì khác với địa chỉ thư? –

3

Hãy thử này

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

Tôi Hy vọng nó có thể hữu ích ...

+1

Cảm ơn bạn đã trợ giúp ..., – viral

+0

bạn hoan nghênh ... – Kamarshad

Các vấn đề liên quan