从地址簿中仅获取移动节目记录(不是来自iphone,家庭标签等)?
问题描述:
如何在ios中从地址簿中仅获取移动节点记录?从地址簿中仅获取移动节目记录(不是来自iphone,家庭标签等)?
我想向移动部分记录中提取的我的阵列添加一条记录。
我该怎么做。我正在获取所有电话资产记录。但我只需要获取移动节目记录。
NSArray *allPeople = (NSArray *)ABAddressBookCopyArrayOfAllPeople(myAddressBook);
NSLog(@"allpeople%@", allPeople);
for (id record in allPeople) {
CFTypeRef phoneProperty = ABRecordCopyValue((ABRecordRef)record, kABPersonPhoneProperty);
NSArray *phones = (NSArray *)ABMultiValueCopyArrayOfAllValues(phoneProperty);
NSLog(@"phones %@",phones);
CFRelease(phoneProperty);
NSMutableDictionary *newRecord = [[NSMutableDictionary alloc] init];
NSMutableString *newPhone = [[NSMutableString alloc] init];
for (NSString *phone in phones) {
if(![newPhone isEqualToString:@""])
[newPhone appendString:@", "];
[newPhone appendString:phone];
}
答
你可以尝试这样的事情..
ABMultiValueRef phoneNumbers = ABRecordCopyValue(abPerson, kABPersonPhoneProperty);
if (phoneNumbers) {
CFIndex numberOfPhoneNumbers = ABMultiValueGetCount(phoneNumbers);
for (CFIndex i = 0; i < numberOfPhoneNumbers; i++) {
NSString *phone = (__bridge_transfer NSString *)ABMultiValueCopyValueAtIndex(phoneNumbers, i);
CFStringRef label = ABMultiValueCopyLabelAtIndex(phoneNumbers, i);
if (label) {
if (CFEqual(label, kABPersonPhoneMobileLabel)) {
primaryPhoneText.text = phone;
} else {
}
CFRelease(label);
[allPhones addObject:phone]; // allPhones is an array here.
}
}
CFRelease(phoneNumbers);
}
希望这将帮助你..
享受编码..
+0
这是我的工作代码.. – Shivaay
你想获取从地址簿中的手机号码? – Shivaay
@popeye是啊只有手机号码从地址簿 – user2401659
那么你为什么不想使用(abPerson,kabpersonphonemobilelabel)? – Shivaay