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