ABCreateStringWithAddressDictionary弃用

即时通讯使用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)"

}

回答:

要使用CNPostalAddressFormatter,您需要传递一个CNPostalAddress。要创建一个CNPostalAddress,您真正需要使用CNMutablePostalAddress:

func printMiamiFL() 

{

let theAddress = CNMutablePostalAddress()

theAddress.city = "Miami"

theAddress.state = "FL"

let formatter = CNPostalAddressFormatter()

let addressString = formatter.string(from: theAddress)

print(addressString)

}

所以,你需要创建一个地址对象,并从你的字典用数据填充它,然后事情应该很好地工作。

以上是 ABCreateStringWithAddressDictionary弃用 的全部内容, 来源链接: utcz.com/qa/266930.html

回到顶部