1

我正在开发一个打开用户通讯录的 iPhone 应用程序,它获取用户从电话簿中选择的人的电话号码。如果通讯簿中有一个人有 2 个或更多电话号码并且用户删除了其中一个联系人,并且在该用户从该人那里选择了联系人之后,那么“ABPeoplePickerNavigationControllerDelegate”方法 -

(void)peoplePickerNavigationController:(ABPeoplePickerNavigationController*)peoplePicker didSelectPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier NS_AVAILABLE_IOS(8_0);

给出错误的标识符。否则它工作正常。

这是我用来从通讯簿中获取所选电话号码的代码。有人知道为什么委托方法没有给出正确的标识符吗?

- (void)peoplePickerNavigationController:(ABPeoplePickerNavigationController*)peoplePicker didSelectPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier
{

if (property == kABPersonPhoneProperty)
{
    NSString* phoneNumber = nil;

    ABMultiValueRef phoneNumbers = ABRecordCopyValue(person,
                                                     property);

    if (ABMultiValueGetCount(phoneNumbers) > 0)
    {
        CFIndex index = ABMultiValueGetIndexForIdentifier(phoneNumbers, identifier);

 *//****  since identifier is wrong it returns index as -1 and app crashes in the below line *****
        phoneNumber = (__bridge_transfer NSString*) ABMultiValueCopyValueAtIndex(phoneNumbers, index);
    }

}

4

0 回答 0