0
저는 (iOS6을 사용하는) iphone 앱 개발을 처음 접했고 연락처 목록에서 UITableViewController로 휴대폰 번호를 가져 오는 데 어려움을 겪고 있습니다. 이름과 성을 올바르게 입력 할 수 있지만 전화 번호는 null로 반환됩니다. 이것 뒤에있는 이유를 이해할 수 없었다. 내가 뭘 잘못하고있는 걸까? 여기연락처 목록에서 휴대폰 번호를 가져올 수 없습니다. 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;