我遇到问题我的应用程序崩溃试图保存通讯簿。崩溃是由EXC_BAD_ACCESS
造成的,并且由于呼叫ABCDBContextSaveMultiValue
CFArrayGetCount(...)
期间发生
因此,我认为我已经解决了问题,但不知道如何解决它。这是我的代码:
ABAddressBookRef addressBook = ABAddressBookCreate();
for (int i=0; i<[pledgeInfo count]; i++ ) {
NSArray * pledgeObj = [pledgeInfo objectAtIndex:i];
ABRecordRef personRef = ABPersonCreate();
CFErrorRef error = NULL;
if( !ABRecordSetValue(personRef, kABPersonFirstNameProperty, [pledgeObj objectAtIndex:1], &error) ) {/*ErrorHandle*/}
if( !ABRecordSetValue(personRef, kABPersonLastNameProperty, [pledgeObj objectAtIndex:2], &error) ) {/*ErrorHandle*/}
if( !ABRecordSetValue(personRef, kABPersonEmailProperty, [pledgeObj objectAtIndex:4], &error) ) {/*ErrorHandle*/}
// ERROR IS IN HERE SOMEWHERE
ABMutableMultiValueRef phNums = ABMultiValueCreateMutable(kABMultiStringPropertyType);
ABMultiValueIdentifier abi;
if( !ABMultiValueAddValueAndLabel(phNums, [pledgeObj objectAtIndex:3], kABPersonPhoneMobileLabel, &abi) ) {/*ErrorHandle*/}
if( !ABRecordSetValue(personRef, kABPersonPhoneProperty, phNums, &error) ) {/*ErrorHandle*/}
if( !ABAddressBookAddRecord(addressBook, personRef, &error) ) {/*ErrorHandle*/}
}
NSLog(@"%@",addressBook);
CFErrorRef cferr = NULL;
if( !ABAddressBookSave(addressBook, &cferr) ) {/*ErrorHandle*/
}