简体   繁体   English

如何检查通讯录中的联系人在iOS中是否有多个号码?

[英]How to check if a contact in Address Book has multiple numbers in iOS?

I have a requirement to determine if a contact that is saved in the address book has multiple mobile numbers. 我需要确定通讯簿中保存的联系人是否具有多个手机号码。

I have the record ID of a Contact and I need to check if that contact has multiple mobile numbers. 我有一个联系人的记录ID,我需要检查该联系人是否有多个手机号码。

Is this possible? 这可能吗?

Got the Answer!!! 得到了答案!!! I have written a method to get the total count of mobile numbers for a contact 我已经编写了一种获取联系人移动电话总数的方法

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM