0
即时通讯使用ABCreateStringWithAddressDictionary建立一个地址,但即时通讯有问题,因为我试过使用cnpostaladressformatter但有一些错误。你能告诉我如何使用cnpostaladressformatter来升级下面的代码。ABCreateStringWithAddressDictionary弃用
if let addressDic = placemark.addressDictionary {
if let lines = addressDic["FormattedAddressLines"] as? [String] {
return lines.joined(separator: " • ")
} else {
// fallback
return ABCreateStringWithAddressDictionary(addressDic, true)
}
} else {
return "\(coordinate.latitude), \(coordinate.longitude)"
}
对我来说,你必须创建一个CNPostalAddress对象并从你的addressDic中填充它的属性(城市,州等)。然后你可以使用CNPostalAddressFormatter中的“string(from)”方法。 – ghostatron
fwiw,CNContact框架在iOS 9中被添加,比AB的东西更友好,这就是为什么你会看到使用弃用警告的原因。 AB代码你有。 – ghostatron
@ghostatron你可以告诉我如何解决它,这是我的问题,现在 – john