如何获得我在ABPeoplePickerView中选择的人的地址值(城市、街道、拉链)?
let person = PeoplePicker.selectedRecords as! [ABPerson]
print(person[0].value(forProperty: "First"))
print(person[0].value(forProperty: "Last"))
print(person[0].value(forProperty: "Address"))这是我的打印结果:
Max
Mustermann
{
* home {
City = xxx;
Street = "xxx";
ZIP = xxx;
} D
}现在编码:
let addressBook = ABAddressBook.shared()
let people = addressBook?.people()
for person in people! as! [ABPerson] {
for property in ABPerson.properties() {
if let multiValue = person.value(forProperty: (property as! NSString) as String!) as? ABMultiValue {
for identifier in multiValue {
let value: AnyObject = multiValue.valueForIdentifier(identifier as String)
print("\(identifier) : \(value)")
}
}
}
}错误:
Type 'ABMultiValue' does not conform to protocol 'Sequence'
on line: for identifier in multiValue {发布于 2017-07-01 12:06:34
解决办法是:
let address = person[0].value(forProperty: kABAddressProperty) as! ABMultiValue
let zip = address.value(at: 0) as! NSMutableDictionary
print(y.value(forKey: kABAddressZIPKey))发布于 2017-06-28 10:56:01
参考此示例,并对单个联系人进行修改。
let addressBook = ABAddressBook.sharedAddressBook()
let people = addressBook.people()
for person in people {
for property in ABPerson.properties() {
if let multiValue = person.valueForProperty(property as NSString) as? ABMultiValue {
for identifier in multiValue {
let value: AnyObject = multiValue.valueForIdentifier(identifier as String)
println("\(identifier) : \(value)")
}
}
}
}发布于 2017-06-28 11:29:52
Get值是一个带有邮政地址值的标记值数组。邮政地址有“街道”财产、“城市”财产、“国家”财产、“postalCode”财产、“国家”财产。
let array = person[0].value(forProperty: "Address") as! NSarray使用标签值获取该值,您可以获得像城市、州和邮政编码这样分开的名称。
https://stackoverflow.com/questions/44800031
复制相似问题