如何在Mac OS X地址簿中访问有关联系人的信息?

时间:2016-07-20 16:21:33

标签: swift macos abaddressbook

尝试在Mac上的地址簿中查找联系人时,会显示以下编译器错误“使用未解析的标识符'kABPersonFirstNameProperty'。”我找到了一个适用于iOS的示例here,但找不到与OS X等效的版本。根据文档,我已安装的OS X(10.10.5)版本中提供了ABRecordCopyValue

if let book = ABAddressBook.sharedAddressBook() {
    let nameIsSmith = ABPerson.searchElementForProperty(kABLastNameProperty, label: nil, key: nil, value: "Smith", comparison: ABSearchComparison(kABEqualCaseInsensitive.rawValue))

    let peopleFound = book.recordsMatchingSearchElement(nameIsSmith)

    for person in peopleFound {
        let firstName = ABRecordCopyValue(book, kABPersonFirstNameProperty).takeRetainedValue() as? String
    }
}

0 个答案:

没有答案