如何在 JavaScript for Automation 中使用 ObjC 桥接联系人框架?我可以使用旧的 AddressBook 框架,但不能使用 Contacts 框架。
假设我有一个 ID:
id = Application("Contacts").myCard().id()
旧的 AddressBook 框架运行良好:
ObjC.import("AddressBook");
book = $.ABAddressBook.addressBook
person = book.recordForUniqueId(id)
console.log(person.valueForProperty($.kABFirstNameProperty).js)
但是如何使用联系人框架呢?我试过(基于文档unifiedContactWithIdentifier
):
ObjC.import('Contacts')
keysToFetch = [ $.CNContactGivenNameKey, $.CNContactFamilyNameKey ]
store = $.CNContactStore
store.unifiedContactWithIdentifierKeysToFetchError( id, keysToFetch, null )
...
这将失败并出现错误 -2700:脚本错误。弹出窗口说TypeError: store.unifiedContactWithIdentifierKeysToFetchError is not a function
编辑:一个更基本的例子,该defaultContainerIdentifier
方法给出了一个undefined
输出:
ObjC.import('Contacts')
store = $.CNContactStore
console.log(store)
/* [Class CNContactStore] */
console.log(store.defaultContainerIdentifier)
/* undefined */