0
我是iphone應用程序開發(使用iOS6)的新手,並且一直面臨將聯繫人列表中的移動號碼獲取到UITableViewController中的問題。我可以正確地得到名字和姓氏,但電話號碼被返回爲空。我無法理解這背後的原因。我做錯了什麼?我的代碼如下:無法從聯繫人列表中獲取手機號碼。 iOS6
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;