私はiPhoneアプリ開発(iOS6を使用)が初めてで、連絡先リストからUITableViewControllerに携帯電話番号を取得する際に問題に直面しています。名と姓は正しく取得できますが、電話番号は null として返されます。この背後にある理由を理解できませんでした。何が間違っているのですか? 私のコードは次のとおりです。
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;