[英]use objC bridge Contacts framework in JavaScript for Automation
How do I use the ObjC bridge Contacts framework in JavaScript for Automation? 如何在JavaScript for Automation中使用ObjC bridge Contacts框架? I am able to use the old AddressBook framework, but not the Contacts one.
我可以使用旧的AddressBook框架,但不能使用Contacts框架。
Let's say I have an ID: 假设我有一个ID:
id = Application("Contacts").myCard().id()
The old AddressBook framework works fine: 旧的AddressBook框架可以正常工作:
ObjC.import("AddressBook");
book = $.ABAddressBook.addressBook
person = book.recordForUniqueId(id)
console.log(person.valueForProperty($.kABFirstNameProperty).js)
But how to use the Contacts framework? 但是如何使用联系人框架? I tried (based on the documentation for
unifiedContactWithIdentifier
): 我试过了(根据
unifiedContactWithIdentifier
的文档):
ObjC.import('Contacts')
keysToFetch = [ $.CNContactGivenNameKey, $.CNContactFamilyNameKey ]
store = $.CNContactStore
store.unifiedContactWithIdentifierKeysToFetchError( id, keysToFetch, null )
...
This fails with Error -2700: Script error. 这将失败,并显示错误-2700:脚本错误。 The popup says
TypeError: store.unifiedContactWithIdentifierKeysToFetchError is not a function
弹出窗口显示
TypeError: store.unifiedContactWithIdentifierKeysToFetchError is not a function
Edit : an even more basic example, the defaultContainerIdentifier
method gives an undefined
output: 编辑 :一个更基本的示例,
defaultContainerIdentifier
方法提供了undefined
输出:
ObjC.import('Contacts')
store = $.CNContactStore
console.log(store)
/* [Class CNContactStore] */
console.log(store.defaultContainerIdentifier)
/* undefined */
In the first case you get an instance of the class using a class method +addressBook
. 在第一种情况下,您可以使用类方法
+addressBook
获得该类的实例。 In the second case you have no instance and you are trying to call an instance method. 在第二种情况下,您没有实例,并且试图调用实例方法。 You cannot call instance methods on a class.
您不能在类上调用实例方法。
I suppose you have to create a new instance using: 我想您必须使用以下方法创建一个新实例:
store = $.CNContactStore.alloc.init
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.