Iphone 如何从addressbook IOS 5 KabbersonPhoneProperty获取所有电话号码
我正在使用KabbersonPhoneProperty从通讯簿中获取iPhone的“电话号码”。然而,一旦我运行该程序,只有一个电话号码出现,即使联系人有手机、家庭和iphone号码。请帮忙,我希望能从每个联系人那里得到所有的电话号码。谢谢 完整方法:Iphone 如何从addressbook IOS 5 KabbersonPhoneProperty获取所有电话号码,iphone,objective-c,ios5,xcode4.3,Iphone,Objective C,Ios5,Xcode4.3,我正在使用KabbersonPhoneProperty从通讯簿中获取iPhone的“电话号码”。然而,一旦我运行该程序,只有一个电话号码出现,即使联系人有手机、家庭和iphone号码。请帮忙,我希望能从每个联系人那里得到所有的电话号码。谢谢 完整方法: - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSStri
- (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;
}
-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
{
静态NSString*simpleTableIdentifier=@“SimpleCell”;
UITableViewCell*单元格=[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
如果(单元格==nil){
cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault重用标识符:simpleTableIdentifier];
}
//cell.textlab.text=[people objectAtIndex:indexath.row];
ABRecordRef记录=(uu-bridge ABRecordRef)[people-objectAtIndex:[indexPath行];
NSString*firstName=(uu_桥_传输NSString*)ABRECORDCYVALUE(记录,KabbersonfirstNameProperty);
NSString*lastName=(\uuuuu桥\uu传输NSString*)ABRecordCopyValue(记录,kABPersonLastNameProperty);
NSLog(@“FirstName%@,LastName%@”,FirstName,LastName);
cell.namelab.text=[NSString stringWithFormat:@“%@%@”,firstName,lastName];
ABMultiValueRef mainPhone=ABRecordCopyValue(记录,KabPersonPhone属性);
对于(CFIndex i=0;i
好这里是解决方案
` ABAddressBookRef addressBook=ABAddressBookCreate();
NSArray *allPeople=(NSArray *)ABAddressBookCopyArrayOfAllPeople(addressBook);
NSMutableArray *holdEachPersonMobileNumbers=[NSMutableArray new];
for (id person in allPeople) {
ABMultiValueRef phoneNumbers = ABRecordCopyValue(( ABRecordRef)(person), kABPersonPhoneProperty);
NSString* mobile=@"";
for (int i=0; i < ABMultiValueGetCount(phoneNumbers); i++) {
mobile = (NSString*)ABMultiValueCopyValueAtIndex(phoneNumbers, i);
NSCharacterSet *trim = [NSCharacterSet characterSetWithCharactersInString:@"#();$&-+"];
mobile = [[mobile componentsSeparatedByCharactersInSet: trim] componentsJoinedByString: @""];
mobile= [mobile stringByReplacingOccurrencesOfString:@"\"" withString:@""];
mobile=[mobile stringByReplacingOccurrencesOfString:@" " withString:@""];
[holdEachPersonMobileNumbers addObject:mobile];
}
}
`ABAddressBookRef addressBook=ABAddressBookCreate();
NSArray*allPeople=(NSArray*)ABAddressBookCopyArrayOfAllPeople(addressBook);
NSMutableArray*HoldeAchPersonMobileNumber=[NSMutableArray new];
for(所有人中的id人){
ABMultiValueRef phoneNumbers=ABRecordCopyValue((ABRecordRef)(person),kABPersonPhoneProperty);
NSString*mobile=@;
对于(int i=0;i
`
此处保存每个人的手机号码保存与您在通讯簿中选择的特定人相关的所有号码
将上述代码放入此方法中
-(BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController*)peoplePickerNavigationController在选择person:(ABRecordRef)person后应继续
希望您遵守本协议
和导入此文件
#import <AddressBook/AddressBook.h>
#import <AddressBookUI/AddressBookUI.h>
#导入
#进口
文本应该显示在哪里?在tableview单元格中?在tableview单元格中是,并且tableview单元格中有联系人姓名和联系人号码字段。如何生成联系人号码(所有类型的联系人号码,包括Main、Mobile和Iphone)可以显示在联系人号码字段中吗?这是在
方法中吗?我正在(UITableViewCell*)tableView:(UITableView*)tableView CellForRowatineXpath:(NSIndexPath*)协议中的indexPath中实现。您可以发布整个CellForRowatineXpath:
方法吗?