如何检查地址簿中的联系人是否在iOS中有多个号码?

时间:2015-10-07 08:06:19

标签: ios addressbook

我需要确定通讯录中保存的联系人是否有多个手机号码。

我有联系人的记录ID,我需要检查该联系人是否有多个手机号码。

这可能吗?

1 个答案:

答案 0 :(得分:0)

得到了答案!我已经编写了一种方法来获取联系人的手机号码总数

-(NSInteger)getCountOfTotalMobileNumbersForContact:(ContactData *)contactData{
NSInteger totalCountOfMobileNumbers = 0;

ABAddressBookRef addressBook = ABAddressBookCreateWithOptions(NULL, NULL);
ABRecordRef contact = ABAddressBookGetPersonWithRecordID(addressBook, (int)contactData.mRecordID);
if(contact != nil)
{
    self.phoneNumbers = ABRecordCopyValue(contact, kABPersonPhoneProperty);
    NSString *lFirstName = (__bridge_transfer NSString*)ABRecordCopyValue(contact, kABPersonFirstNameProperty);
    NSString *lLastName = (__bridge_transfer NSString*)ABRecordCopyValue(contact, kABPersonLastNameProperty);

    NSString *fullName = lFirstName;

    if (lLastName.length) {
        fullName = [[lFirstName stringByAppendingString:@" "] stringByAppendingString:lLastName];
    }
    totalCountOfMobileNumbers = ABMultiValueGetCount(self.phoneNumbers);
}

return totalCountOfMobileNumbers;
}