iOS目标C:从CNContactProperty获取用户选择的电话号码作为字符串

时间:2017-03-14 03:35:56

标签: ios cncontact

我的问题与此处的问题基本相同:

iOS Swift: Get user selected phone number from CNContactProperty as a string

在没有解决方案的情况下被错误地标记为重复(原因在该帖子中说明)。

我非常想知道答案,应该很简单,因为我可以看到Skype使用完全相同的API来检索联系人,我想知道如何。

Swift或Objective C并不重要,只有这个想法很重要,谢谢。

1 个答案:

答案 0 :(得分:2)

经过几个小时的尝试,我自己想出来了:

我们首先需要获得"标识符" CNContactProperty的属性,然后获取与之匹配的所选数字。

- (void)contactPicker:(CNContactPickerViewController *)picker didSelectContactProperty:(CNContactProperty *)contactProperty {
    CNContact *contact = contactProperty.contact;
    NSString *identify = contactProperty.identifier;//pick the number according to this id!!!
    _lastDisplay = @"";
    for (CNLabeledValue<CNPhoneNumber*>* number in contact.phoneNumbers) {
        if ([number.identifier isEqualToString:identify]) {
            _lastDisplay = ((CNPhoneNumber *)number.value).stringValue;
        }
    }
}

如果有人需要,请留在这里。