0
我正在使用ABPeoplePickerNavigationController從通訊錄條目中收集一組電子郵件地址和電話號碼。 90%的時間工作正常,但少數測試人員報告崩潰。崩潰報告稱它正在CFRelease崩潰...不知道爲什麼考慮我相信我的代碼是正確的。請看:ABPeoplePickerNavigationController EXC_BAD_ACCESS收集電子郵件和電話號碼
ABProfile *selectedUser = [[ABProfile alloc]init];
ABMultiValueRef emails = ABRecordCopyValue(person, kABPersonEmailProperty);
NSArray *emailArray;
if (ABMultiValueGetCount(emails) > 0) {
emailArray = (__bridge_transfer NSArray *)ABMultiValueCopyArrayOfAllValues(emails);
}
CFRelease(emails);
ABMultiValueRef phones = ABRecordCopyValue(person, kABPersonPhoneProperty);
NSMutableArray *phonesArray = [[NSMutableArray alloc]initWithCapacity:1];
for(CFIndex j = 0; j < ABMultiValueGetCount(phones); j++)
{
NSMutableDictionary *dict = [[NSMutableDictionary alloc]initWithCapacity:1];
CFStringRef phoneNumberRef = ABMultiValueCopyValueAtIndex(phones, j);
CFStringRef locLabel = ABMultiValueCopyLabelAtIndex(phones, j);
NSString *phoneLabel =(__bridge_transfer NSString*) ABAddressBookCopyLocalizedLabel(locLabel);
CFRelease(locLabel);
[dict setValue:phoneLabel forKey:@"label"];
NSString *phoneNumber = (__bridge_transfer NSString *)phoneNumberRef;
[dict setValue:phoneNumber forKey:@"number"];
[phonesArray addObject:dict];
}
selectedUser.phones = phonesArray;
CFRelease(phones);