我需要联系人的住址。我知道如何获取单值属性,但是街道地址是一个多值属性。Apple的文档展示了如何设置它,但不是检索它。有什么帮助吗?
PS:这不起作用:
ABRecordCopyValue(person, kABPersonAddressStreetKey);发布于 2011-12-02 23:36:03
我刚想通了:
ABMultiValueRef st = ABRecordCopyValue(person, kABPersonAddressProperty);
if (ABMultiValueGetCount(st) > 0) {
    CFDictionaryRef dict = ABMultiValueCopyValueAtIndex(st, 0);
    self.street.text = CFDictionaryGetValue(dict, kABPersonAddressStreetKey);
}发布于 2015-08-29 20:33:34
Swift版本:
    if let addresses : ABMultiValueRef = ABRecordCopyValue(person, kABPersonAddressProperty)?.takeRetainedValue() as ABMultiValueRef? where ABMultiValueGetCount(addresses) > 0 {
        for index in 0..<ABMultiValueGetCount(addresses){
            if let address = ABMultiValueCopyValueAtIndex(addresses, index)?.takeRetainedValue() as? [String:String],
                label = ABMultiValueCopyLabelAtIndex(addresses, index)?.takeRetainedValue()  as? String{
                    print("\(label): \(address) \n")
            }
        }
    }您可以通过提供对应的key来访问单独的地址字段:
let street  = address[kABPersonAddressStreetKey as String]
let city    = address[kABPersonAddressCityKey as String]
let state   = address[kABPersonAddressStateKey as String]
let zip     = address[kABPersonAddressZIPKey as String]
let country = address[kABPersonAddressCountryKey as String]
let code    = address[kABPersonAddressCountryCodeKey as String]发布于 2016-10-21 15:23:08
Swift 3.0
//Extract billing address from ABRecord format and assign accordingly
let addressProperty: ABMultiValue = ABRecordCopyValue(billingAddress, kABPersonAddressProperty).takeUnretainedValue() as ABMultiValue
if let dict: NSDictionary = ABMultiValueCopyValueAtIndex(addressProperty, 0).takeUnretainedValue() as? NSDictionary {
     print(dict[String(kABPersonAddressStreetKey)] as? String)
     print(dict[String(kABPersonAddressCityKey)] as? String)
     print(dict[String(kABPersonAddressStateKey)] as? String)
     print(dict[String(kABPersonAddressZIPKey)] as? String)
     print(dict[String(kABPersonAddressCountryKey)] as? String) //"United States"
}https://stackoverflow.com/questions/8329006
复制相似问题