iOS:cncontactpicker didSelect-如何确定所选属性的类型



我正在尝试通过检查将传递给协议函数的cncontactproperty检查与cncontactproperty进行相互作用时,他们选择了哪种类型的属性。

即。告诉用户是否选择了电话号码,或发送电子邮件等。

public func contactPicker(_ picker: CNContactPickerViewController, didSelect theContactProperty: CNContactProperty){
    if theContactProperty. == CNContactPhoneNumbersKey { // This doesn't work!!
        // Do stuff when we've received a phone number
    }
    else { 
        // Do other stuff when we have received something other than a phone number
    }
}

我上面使用过的" if"语句不起作用。知道为什么?

我如何确定用户从"接触派选项"屏幕中选择了哪种类型的属性?

解决方案:

if theContactProperty.key == CNContactPhoneNumbersKey {
}

最新更新