gpt4 book ai didi

iphone - 如何从通讯录 IOS 5 KA PersonPhone 属性中获取所有电话号码

转载 作者:行者123 更新时间:2023-12-03 21:16:50 24 4
gpt4 key购买 nike

我正在使用 kABPersonPhoneProperty 从地址簿中获取 iPhone“电话号码”。然而,一旦我运行该程序,即使联系人有手机号码、家庭号码和 iPhone 号码,也只出现一个电话号码。请帮忙,我希望能得到每个联系人的所有电话号码。谢谢。

完整方法:

- (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;

}

最佳答案

好的,这是解决方案

`    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];
}

}

`

此处holdEachPersonMobileNumbers保存与您在地址簿中选择的特定人员关联的所有号码

将上面的代码放入此方法中- (BOOL)peoplePickerNavigationController: (ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person

希望你遵守这个协议(protocol)ABPeoplePickerNavigationControllerDelegate导入这个

    #import <AddressBook/AddressBook.h>
#import <AddressBookUI/AddressBookUI.h>

关于iphone - 如何从通讯录 IOS 5 KA PersonPhone 属性中获取所有电话号码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11277242/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com