我正在使用 kABPersonPhoneProperty 从通讯簿中获取 iPhone“电话号码”。然而,一旦我运行该程序并且只有一个电话号码出现,即使联系人有手机、家庭和 iphone 号码。请帮忙,我希望能从每个联系人那里得到所有的电话号码。谢谢。
完整的方法:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = @"SimpleCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}
// cell.textLabel.text = [people objectAtIndex:indexPath.row];
ABRecordRef record = (__bridge ABRecordRef) [people objectAtIndex:[indexPath row]];
NSString *firstName = (__bridge_transfer NSString*)ABRecordCopyValue(record, kABPersonFirstNameProperty);
NSString *lastName = (__bridge_transfer NSString*)ABRecordCopyValue(record, kABPersonLastNameProperty);
NSLog(@"FirstName %@, LastName %@", firstName, lastName);
cell.nameLabel.text = [NSString stringWithFormat:@"%@ %@", firstName, lastName];
ABMultiValueRef mainPhone = ABRecordCopyValue(record, kABPersonPhoneProperty);
for (CFIndex i = 0; i < ABMultiValueGetCount(mainPhone); i ++) {
NSString *phoneMobileNumber = (__bridge_transfer NSString*)ABMultiValueCopyValueAtIndex(mainPhone, i);
cell.telNo.text = [NSString stringWithFormat:@"%@ %@" , home, phoneMobileNumber];
NSLog(@"%@,%@", home, phoneMobileNumber);
}
return cell;
}