我正在尝试使用通讯录(Swift)获取自定义标签电话号码。
我已经尝试了kABOtherLabel属性,但是没有得到想要的结果。
我想知道是否有方法可以获取自定义标签属性..?
这里我分享一下我目前在做什么。
提前感谢。
//phone
var phones : ABMultiValueRef = ABRecordCopyValue(contactRef,kABPersonPhoneProperty).takeUnretainedValue() as ABMultiValueRef
for(var numberIndex : CFIndex = 0; numberIndex < ABMultiValueGetCount(phones); numberIndex++)
{
// Number in contact details of current index
let phoneUnmaganed = ABMultiValueCopyValueAtIndex(phones, numberIndex)
let phoneNumber : NSString = phoneUnmaganed.takeUnretainedValue() as! NSString
// Label of Phone Number
let locLabel : CFStringRef = (ABMultiValueCopyLabelAtIndex(phones, numberIndex) != nil) ? ABMultiValueCopyLabelAtIndex(phones, numberIndex).takeUnretainedValue() as CFStringRef : ""
//check for home
if (String(locLabel) == String(kABHomeLabel))
{
contact.sUserTelHome = phoneNumber as String
contact.sUserTelHomeTrim = contact.sUserTelHome?.trimmedContactNumber()
}
//check for work
else if (String(locLabel) == String(kABWorkLabel))
{
contact.sUserTelWork = phoneNumber as String
contact.sUserTelWorkTrim = contact.sUserTelWork?.trimmedContactNumber()
}
//check for mobile
else if (String(locLabel) == String(kABPersonPhoneMobileLabel))
{
contact.sUserTelMobile = phoneNumber as String
contact.sUserTelMobileTrim = contact.sUserTelMobile?.trimmedContactNumber()
}
else if(String(locLabel) == String(kABOtherLabel)){
}
}