我是 iphone App Development(使用 iOS6)的新手,并且在将手机号码从联系人列表中提取到 UITableViewController 时遇到了问题。我可以正确获取名字和姓氏,但电话号码返回为空。我无法理解这背后的原因。我做错了什么?我的代码如下:
NSMutableArray *people = (__bridge_transfer NSMutableArray *) ABAddressBookCopyArrayOfAllPeople (addressBookRef);
NSString *firstName = (__bridge_transfer NSString *)ABRecordCopyValue((__bridge ABRecordRef)([people objectAtIndex:indexPath.row]), kABPersonFirstNameProperty);
NSString *lastName = (__bridge_transfer NSString *)ABRecordCopyValue((__bridge ABRecordRef)([people objectAtIndex:indexPath.row]), kABPersonLastNameProperty);
ABMultiValueRef phoneNumbers = ABRecordCopyValue((__bridge ABRecordRef)([people objectAtIndex:indexPath.row]),kABPersonPhoneProperty);
if (([firstName isEqualToString:@""] || [firstName isEqualToString:@"(null)"] || firstName == nil) &&
([lastName isEqualToString:@""] || [lastName isEqualToString:@"(null)"] || lastName == nil))
{
// do nothing
}
else
{
aName = [NSString stringWithFormat:@"%@ %@", firstName, lastName];
if ([firstName isEqualToString:@""] || [firstName isEqualToString:@"(null)"] || firstName == nil)
{
aName = [NSString stringWithFormat:@"%@", lastName];
}
if ([lastName isEqualToString:@""] || [lastName isEqualToString:@"(null)"] || lastName == nil)
{
aName = [NSString stringWithFormat:@"%@", firstName];
}
//[self.tableItems addObject:aName];
NSLog(@"%@ added",aName);
}
//fetch multiple phone nos. and use only 0th
id person = people[indexPath.row];
ABMultiValueRef multi = ABRecordCopyValue((__bridge ABRecordRef)(person), kABPersonPhoneProperty);
NSString* phone = (__bridge NSString*)ABMultiValueCopyValueAtIndex(multi, 0);
NSLog(@"%@",phone);
[cell.detailTextLabel setText:phone];
[cell.textLabel setText:aName];
return cell;