【发布时间】:2021-08-20 14:29:30
【问题描述】:
我正在编写一个扩展程序,主应用程序在 PyObjc 中。我想设置主应用程序和扩展程序之间的通信。 参考link,我尝试编写协议。
SampleExtensionProtocol = objc.formal_protocol('SampleExtensionProtocol', (), [
objc.selector(None, b"upperCaseString:withReply:", signature=b"v@:@@",isRequired=0),
objc.selector(None, b"setEnableTemperProof:withReply:", signature=b"v@:@@",isRequired=0),
])
连接对象已创建。
connection = NSXPCConnection.alloc().initWithMachServiceName_options_("com.team.extension",NSXPCConnectionPrivileged)
注册元数据也是如此。
objc.registerMetaDataForSelector(b'NSObject', b'upperCaseString:withReply:', {
'arguments': {
3: {
'callable': {
'retval': {'type': b'@'},
'arguments': {
0: {'type': b'^v'},
1: {'type': b'i'},
},
},
}
}
})
objc.registerMetaDataForSelector(b'NSObject', b'setEnableTemperProof:withReply:', {
'arguments': {
3: {
'callable': {
'retval': {'type': b'@'},
'arguments': {
0: {'type': b'^v'},
1: {'type': b'i'},
},
},
}
}
})
但是在创建接口时出错。
mySvcIF = Foundation.NSXPCInterface.interfaceWithProtocol_(SampleExtensionProtocol)
ValueError: NSInvalidArgumentException - NSXPCInterface: Unable to get extended method signature from Protocol data (SampleExtensionProtocol / upperCaseString:withReply:). Use of clang is required for NSXPCInterface.
【问题讨论】:
-
PyObjC 作者在这里。看起来 NSXPCInterface 需要 PyObjC 目前不提供的信息。我必须调查这里发生了什么,以及是否可以提供来自 PyObjC 的扩展信息。
-
一种解决方法是在使用 clang 编译的小型 C 扩展中定义协议。不是很好,但至少你可以继续。
标签: macos pyobjc nsxpcconnection