首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >“kABPersonAddressStreetKey”在iOS 9.0中被废弃:使用CNPostalAddress.street

“kABPersonAddressStreetKey”在iOS 9.0中被废弃:使用CNPostalAddress.street
EN

Stack Overflow用户
提问于 2015-06-27 04:55:20
回答 4查看 7.7K关注 0票数 15

下面的课程是用Swift的早期版本编写的。Swift 2编译器警告说

'kABPersonAddressStreetKey‘在iOS 9.0:use CNPostalAddress.street中被否决

并给出一个错误

“无法为类型”MKPlacemark“找到接受类型参数列表的初始化程序”(坐标: CLLocationCoordinate2D,addressDictionary: String :String?)

我意识到选项者需要解决错误,但无论我尝试什么,似乎都解决不了问题。这是由于我是一个新手,迅速和任何帮助,将不胜感激。

代码语言:javascript
复制
import Foundation
import MapKit
import AddressBook

class Artwork: NSObject, MKAnnotation {
let title: String?
let locationName: String
let discipline: String
let coordinate: CLLocationCoordinate2D

init(title: String, locationName: String, discipline: String, coordinate: CLLocationCoordinate2D) {
    self.title = title
    self.locationName = locationName
    self.discipline = discipline
    self.coordinate = coordinate

    super.init()
}

var subtitle: String? {
    return locationName
}

// annotation callout info button opens this mapItem in Maps app
func mapItem() -> MKMapItem {
    let addressDictionary = [String(kABPersonAddressStreetKey): subtitle]
    let placemark = MKPlacemark(coordinate: coordinate, addressDictionary: addressDictionary)

    let mapItem = MKMapItem(placemark: placemark)
    mapItem.name = title

    return mapItem
  }
}
EN

回答 4

Stack Overflow用户

发布于 2015-06-27 13:47:25

import AddressBook代替import Contacts,用String(CNPostalAddressStreetKey)代替String(kABPersonAddressStreetKey)

代码语言:javascript
复制
import Foundation
import MapKit
import Contacts

class Artwork: NSObject, MKAnnotation {
let title: String?
let locationName: String
let discipline: String
let coordinate: CLLocationCoordinate2D

init(title: String, locationName: String, discipline: String,       coordinate: CLLocationCoordinate2D) {
    self.title = title
    self.locationName = locationName
    self.discipline = discipline
    self.coordinate = coordinate

    super.init()
}

var subtitle: String? {
    return locationName
}

// annotation callout info button opens this mapItem in Maps app
func mapItem() -> MKMapItem {
    let addressDictionary = [String(CNPostalAddressStreetKey): self.subtitle!]
    let placemark = MKPlacemark(coordinate: coordinate, addressDictionary: addressDictionary)
    let mapItem = MKMapItem(placemark: placemark)
    mapItem.name = title

    return mapItem

}
票数 36
EN

Stack Overflow用户

发布于 2016-04-24 21:15:40

你应该使用:

  1. import Contacts而不是import AddressBook
  2. CNPostalAddressStreetKey而不是kABPersonAddressStreetKey
票数 3
EN

Stack Overflow用户

发布于 2016-08-11 01:04:27

在这上面发了雷达。今天收到了这样的答复:

工程提供了有关此问题的下列信息:请知道您应该继续使用废弃的密钥。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31085299

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档