1

我想创建一个允许用户编辑联系人的应用程序。

根据文档CNContactViewController它具有allowsEditingiOS 和macOS 10.11+.

在 Xcode 中,CNContactViewController只有一个属性,没有特定于联系人的方法:

@NSCopying open var contact: CNContact?

ContactsUI是否可以使用框架在 Mac 上编辑联系人,或者这是文档中的错误?

这是我显示联系人的方式:

if let vc = segue.destinationController as? CNContactViewController{

    let contact = CNMutableContact()
    contact.givenName = "John"
    contact.familyName = "Appleseed"

    let homeEmail = CNLabeledValue(label:CNLabelHome, value:"john@example.com" as NSString)
    let workEmail = CNLabeledValue(label:CNLabelWork, value:"j.appleseed@icloud.com" as NSString)
    contact.emailAddresses = [homeEmail, workEmail]

    contact.phoneNumbers = [CNLabeledValue(
        label:CNLabelPhoneNumberiPhone,
        value:CNPhoneNumber(stringValue:"(408) 555-0126"))]

    let homeAddress = CNMutablePostalAddress()
    homeAddress.street = "1 Infinite Loop"
    homeAddress.city = "Cupertino"
    homeAddress.state = "CA"
    homeAddress.postalCode = "95014"
    contact.postalAddresses = [CNLabeledValue(label:CNLabelHome, value:homeAddress)]

    var birthday = DateComponents()
    birthday.day = 1
    birthday.month = 4
    birthday.year = 1988  // You can omit the year value for a yearless birthday
    contact.birthday = birthday
    vc.contact = contact
}

但是,没有可用的编辑按钮:

无编辑按钮

4

1 回答 1

1

我在 Sierra 下使用我的开发人员信用向 Apple 询问了这个问题,得到的答复是 macOS 下还没有实现“编辑”功能。有人建议我提交雷达(我提交了)。我希望它会针对 High Sierra 进行更新,但遗憾的是,还没有这样的 API。

如果您单击实际的“allowsEditing”链接,您将看到对于此 API,它仅在 iOS 下(目前)。可惜 - 我真的很期待删除我的通讯录代码的联系人代码,但我还不能。

于 2017-10-28T22:38:02.613 回答